urllib.请求=>AttributeError:“set”对象没有属性“items”

2024-09-24 20:39:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码中的方法='POST'时出现属性错误urllib.request.request在

我已经尝试了不同的语法:

POST = 'post'
method = POST

method = 'POST'

还有其他。。。在

^{pr2}$

错误输出为:

Traceback (most recent call last):
  File ".\checker netflix.py", line 44, in <module>
    checkPassword(email,password)
  File ".\checker netflix.py", line 23, in checkPassword
    method = POST)
  File "C:\Users\Naylor\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 334, in __init__
    for key, value in headers.items():
AttributeError: 'set' object has no attribute 'items'

我希望请求成功并解析服务器响应,以查看数据的参数是否通过或被拒绝


Tags: 方法代码inpyrequest错误linechecker
1条回答
网友
1楼 · 发布于 2024-09-24 20:39:38

您传递的标头是一个包含字符串的集合:

headers ={"""
    'Host': 'www.netflix.com',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'fr-FR',
    'Accept-Encoding': 'gzip, deflate, br',
    'Referer': 'https://www.netflix.com/fr/',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': 330,
    """}

而不是字典:

^{pr2}$

相关问题 更多 >