马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> import chardet
>>> import urllib.request
>>> response = urllib.request.urlopen('http://www.fishc.com')
>>> detecition = chardet.detect(response)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
detecition = chardet.detect(response)
File "C:\python3.8\lib\site-packages\chardet\__init__.py", line 33, in detect
raise TypeError('Expected object of type bytes or bytearray, got: '
TypeError: Expected object of type bytes or bytearray, got: <class 'http.client.HTTPResponse'>
>>> chardet.detect(response)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
chardet.detect(response)
File "C:\python3.8\lib\site-packages\chardet\__init__.py", line 33, in detect
raise TypeError('Expected object of type bytes or bytearray, got: '
TypeError: Expected object of type bytes or bytearray, got: <class 'http.client.HTTPResponse'>
>>>
出什么问题了
不是传入整个 response 进去。。
detecition = chardet.detect(response.read())
|