Cc L Cc L - 5 months ago 36
Python Question

decode utf8 to big5

every one,I am trying to send sms by python, I can send it,but I need to send in Chinese, which is big5,I have to decode utf8 to big5,here is my sms python code


trydecode.py


import urllib
import urllib2


def sendsms(phonenumber,textcontent):
textcontent.decode('utf8').encode('big5')
url = "https://url?username=myname&password=mypassword&dstaddr="+phonenumber+"&smbody="+textcontent
req = urllib2.Request(url)
response = urllib2.urlopen(req)


this code(python2.7) I can send sms in English but in Chinese (big5) got problem,how can I fix it? thank you

Answer

I think you forgot to save it to change the variable.

textcontent = textcontent.decode('utf8').encode('big5')

Comments