最近在自学python,跟着网上的视频敲着一样的代码既然出错了 下面是报错原因:
request = urllib.request.Request(url=url,headers=headers)
File "F:\python\lib\urllib\request.py", line 334, in init
for key, value in headers.items():
AttributeError: 'set' object has no attribute 'items'
Process finished with exit code 1
大老们麻烦你们帮忙看看这是神马意思?
headers应该写为字典模式,用大括号包裹,你是不是直接用括号包裹了
贴一下你写的headers看看
报错信息指出了集合对象无items属性,因此headers写成了集合类型,应该是像如下以键值对形式的字典样式:
headers={‘user-agent':'Mozilla/5.0','referer':'xxx'}