chardet.detect(response)
>>> 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()) zltzlt 发表于 2020-8-16 15:13
不是传入整个 response 进去。。
谢谢 detecition = chardet.detect(response.read())
页:
[1]