UnicodeDecodeError when passing GET data in Python/AppEngine

后端 未结 2 1952
太阳男子
太阳男子 2021-01-27 11:31

This feels like a really basic question, but I haven\'t been able to find an answer.

I would like to read data from an url, for example GET data from a querystring. I am

相关标签:
2条回答
  • 2021-01-27 11:40

    Check out this blog post on how to do unicode right in Python. In a nutshell, you're trying to decode a byte string (implicitly) as ASCII, and it contains a byte that isn't valid in that codec. Your string is probably in UTF-8.

    0 讨论(0)
  • 2021-01-27 11:41

    You try to e.g. print an ASCII coded string actually containing data of a different charset. This can happen e.g. with Latin-1 encoded data. Try converting your input to unicode using

    unicoded = unicode(non_unicode_string, source_encoding)
    

    where source_encoding is something like 'cp1252', 'iso-8859-1' etc., and sending this to output.

    Have a look at this HOWTO. For a list of encodings supported by Python, see this

    0 讨论(0)
提交回复
热议问题