UnicodeDecodeError: 'utf8' codec can't decode bytes in position 3-6: invalid data

后端 未结 8 1269
谎友^
谎友^ 2020-11-30 00:46

how does the unicode thing works on python2? i just dont get it.

here i download data from a server and parse it for JSON.

Traceback (most recent cal         


        
8条回答
  •  春和景丽
    2020-11-30 01:51

    Temporary workaround: unicode(urllib2.urlopen(url).read(), 'utf8') - this should work if what is returned is UTF-8.

    urlopen().read() return bytes and you have to decode them to unicode strings. Also it would be helpful to check the patch from http://bugs.python.org/issue4733

提交回复
热议问题