UnicodeDecodeError: ascii codec cannot decode byte 0xc3 at position 0: serial number not in range (128)

I am working with google appengine python 2.5.

I am experiencing a unicodedecoderror with the following code, because the name myuser has the following meaning

userName     = unicode(userName).encode('utf-8') # Àºï¼égãwmj is value in this variable  

userName     = unicode(userName).encode('utf-8')
strData = '{\"Sid\" :1, \"Oppid\" :%s, \"Aid\" :%s, \"EC\" :\"%s\", \"Name\" :\%s"' % (enemyID, userID, userEmpCode,userName)


   params = {'deviceToken'   : oDeviceToken,
              'message'       : strMessage,
              'CertificateId' : certificateId,
              'Data'          : strData
             }


result = urlfetch.fetch(url = url,
             payload = urllib.urlencode(params),
             method  = urlfetch.POST,
             headers = {"Authorization" : authString},
             deadline = 30
             )

I am following the steps for the username to encode it in utf-8 so that I can send it as a payload.

username = unicode(username).encode(utf-8)

I believe that an error occurs when I call urllib.urlencode(params)

Please tell us what is going wrong .. or you can ..

and what should be the final strategy for handling unicode string on appengine python ..

I tried different solutions while reading different topics .. but still didn't work

+5
source share
2 answers

, , unicode(userName) , " ", , -, ascii .

, , unicode , unicode, , , .decode .
, isinstance, unicode .

+7

Python 3 Ubuntu Linux 14.04 FreeBSD 10.3. , -, ASCII UTF-8 Python 3.4.4.

encoding='utf-8' open :

open('filepath', encoding='utf-8')
+1

All Articles