0

I have to encode the Arabic text I want to send via SMS so I'm using

import urllib.parse
sms_to_encode = "نتمنى لك رحلة تعليمية ممتعة مع برامجنا الأونلاين"
sms_body = urllib.parse.quote_plus(sms_to_encode)

These are the results:

%D9%86%D8%AA%D9%85%D9%86%D9%89%20%D9%84%D9%83%20%D8%B1%D8%AD%D9%84%D8%A9%20%D8%AA%D8%B9%D9%84%D9%8A%D9%85%D9%8A%D8%A9%20%D9%85%D9%85%D8%AA%D8%B9%D8%A9%20%D9%85%D8%B9%20%D8%A8%D8%B1%D8%A7%D9%85%D8%AC%D9%86%D8%A7%20%D8%A7%D9%84%D8%A3%D9%88%D9%86%D9%84%D8%A7%D9%8A%D9%86

I can send the characters above. but when I plug English character, for example, I want to add the name of the person who registered, and sometimes the person enter an English Name and the encoding will be:

sms_to_encode = "Ahmed نتمنى لك رحلة تعليمية ممتعة مع برامجنا الأونلاين"

Results:

Ahmed%2C%20%D9%86%D8%AA%D9%85%D9%86%D9%89%20%D9%84%D9%83%20%D8%B1%D8%AD%D9%84%D8%A9%20%D8%AA%D8%B9%D9%84%D9%8A%D9%85%D9%8A%D8%A9%20%D9%85%D9%85%D8%AA%D8%B9%D8%A9%20%D9%85%D8%B9%20%D8%A8%D8%B1%D8%A7%D9%85%D8%AC%D9%86%D8%A7%20%D8%A7%D9%84%D8%A3%D9%88%D9%86%D9%84%D8%A7%D9%8A%D9%86

and now I can't send the characters above via SMS.

Any help.

Ahmed
  • 11
  • 1
  • It just added `Ahmed%2C%20`, what's the problem? Why can't you send the new message? Maybe it's a length issue? The new message is 278-character long, whereas the old one was 267, so maybe it's due to that? – Orius Feb 11 '22 at 08:27

1 Answers1

0

Try to using Urllib.Request and Urlopen() functions

response = urllib.request.urlopen(sms_provider, timeout=20)
result = response.read().decode('utf-8').replace(u'\xa9', u'')