代码跟着打报错求助
本帖最后由 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跟着书做下来的代码 发一下代码? AttributeError: 'str' object has no attribute 'items'。
错误告诉你了:属性错误:str没有items这个属性。 res = requests.get(url,headers = headers)
应该是这一句错了吧,我也不太清楚
页:
[1]