def花 发表于 2020-8-16 15:12:00

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'>
>>>
出什么问题了

zltzlt 发表于 2020-8-16 15:13:01

不是传入整个 response 进去。。

detecition = chardet.detect(response.read())

def花 发表于 2020-8-16 15:14:24

zltzlt 发表于 2020-8-16 15:13
不是传入整个 response 进去。。

谢谢

suchocolate 发表于 2020-8-16 15:15:58

detecition = chardet.detect(response.read())
页: [1]
查看完整版本: chardet.detect(response)