我在Python3无法从的urlopen
import urllib.request
f = urllib.request.urlopen("https://www.okcoin.cn/api/v1/trades.do?since=0")
a = f.read() # there is data here
print(a.decode()) # error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
下面的代码,我可以在一个浏览器中得到一个可读的结果为https://www.okcoin.cn/api/v1/trades.do?since=0解码结果。浏览器确认编码是UTF-8。
我错过了什么? 感谢
'requests'库自动处理压缩的数据,请参见本[常见问题](http://www.python-requests.org/en/latest/community/faq/#encoded-data ) –