urllib.urlencode doesn't like unicode values: how about this workaround?

前端 未结 8 759
予麋鹿
予麋鹿 2020-12-12 18:59

If I have an object like:

d = {\'a\':1, \'en\': \'hello\'}

...then I can pass it to urllib.urlencode, no problem:



        
8条回答
  •  余生分开走
    2020-12-12 19:49

    It seems that you can't pass a Unicode object to urlencode, so, before calling it, you should encode every unicode object parameter. How you do this in a proper way seems to me very dependent on the context, but in your code you should always be aware of when to use the unicode python object (the unicode representation) and when to use the encoded object (bytestring).

    Also, encoding the str values is "superfluous": What is the difference between encode/decode?

提交回复
热议问题