鱼C论坛

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

代码跟着打报错求助

[复制链接]
发表于 2020-8-13 01:24:33 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 Bruning 于 2020-8-13 01:25 编辑

Traceback (most recent call last):
  File "D:/py存储库/爬虫/doubanTop250.py", line 62, in <module>
    main()
  File "D:/py存储库/爬虫/doubanTop250.py", line 49, in main
    res = open_url(host)
  File "D:/py存储库/爬虫/doubanTop250.py", line 9, in open_url
    res = requests.get(url,headers = headers)
  File "C:\Users\37984\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\37984\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\37984\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "C:\Users\37984\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\sessions.py", line 449, in prepare_request
    p.prepare(
  File "C:\Users\37984\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\models.py", line 315, in prepare
    self.prepare_headers(headers)
  File "C:\Users\37984\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\models.py", line 447, in prepare_headers
    for header in headers.items():
AttributeError: 'str' object has no attribute 'items'



这什么原因啊 求99  跟着书做下来的代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-13 06:18:56 | 显示全部楼层
发一下代码?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-13 08:22:47 | 显示全部楼层
AttributeError: 'str' object has no attribute 'items'。

错误告诉你了:属性错误:str没有items这个属性。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-13 09:23:47 | 显示全部楼层
    res = requests.get(url,headers = headers)

应该是这一句错了吧,我也不太清楚
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-11 08:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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