我正在尝试遵循本书“挖掘社交网络”1-3的示例代码。twitter趋势api UnicodeDecodeError:'utf8'编解码器无法解码位置1中的字节0x8b:意外的代码字节
[ trend.decode('utf-8') for trend in world_trends()[0]['trends'] ]
和错误信息:
我知道它的老,所以我遵循网页enter link description here
,而且有时候新的样本,我会在我执行的代码遭受错误信息是这样的:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.6-universal/egg/twitter/api.py", line 167, in __call__
File "build/bdist.macosx-10.6-universal/egg/twitter/api.py", line 173, in _handle_response
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: unexpected code byte
它并不总是会发生,但我认为没有程序员喜欢这样的“随机”情况。
所以有谁能帮我解决这个问题?什么是问题以及我如何解决这个问题?
十分感谢〜
我使用python请求见状在库中。 '0x8b'来自gzip头:'1F 8B 08'。有些东西缺少这是gzip压缩数据的事实。 –
更新:这是由于[请求的错误2561](https://github.com/kennethreitz/requests/issues/2561)。 –