鱼C论坛

 找回密码
 立即注册
查看: 1485|回复: 3

[已解决]chardet.detect(response)

[复制链接]
发表于 2020-8-16 15:12:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. >>> import chardet
  2. >>> import urllib.request
  3. >>> response = urllib.request.urlopen('http://www.fishc.com')
  4. >>> detecition = chardet.detect(response)
  5. Traceback (most recent call last):
  6.   File "<pyshell#4>", line 1, in <module>
  7.     detecition = chardet.detect(response)
  8.   File "C:\python3.8\lib\site-packages\chardet\__init__.py", line 33, in detect
  9.     raise TypeError('Expected object of type bytes or bytearray, got: '
  10. TypeError: Expected object of type bytes or bytearray, got: <class 'http.client.HTTPResponse'>
  11. >>> chardet.detect(response)
  12. Traceback (most recent call last):
  13.   File "<pyshell#5>", line 1, in <module>
  14.     chardet.detect(response)
  15.   File "C:\python3.8\lib\site-packages\chardet\__init__.py", line 33, in detect
  16.     raise TypeError('Expected object of type bytes or bytearray, got: '
  17. TypeError: Expected object of type bytes or bytearray, got: <class 'http.client.HTTPResponse'>
  18. >>>
复制代码

出什么问题了
最佳答案
2020-8-16 15:13:01
不是传入整个 response 进去。。

  1. detecition = chardet.detect(response.read())
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-16 15:13:01 | 显示全部楼层    本楼为最佳答案   
不是传入整个 response 进去。。

  1. detecition = chardet.detect(response.read())
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-8-16 15:14:24 | 显示全部楼层
zltzlt 发表于 2020-8-16 15:13
不是传入整个 response 进去。。

谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-16 15:15:58 | 显示全部楼层
  1. detecition = chardet.detect(response.read())
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-25 19:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表