import requests
url = "url"
payload="payload"
headers= headers
response = requests.request("POST",url, headers=headers, data=payload)
authCode = response.headers['authentication]
wurl = "wurl"
wpayload = "wpayload"
wheaders = {
'Cookie': 'Cookie',
'User-Agent: 'User-Agent',
'Authentication' : authCode,
}
wresponse = requests.request("POST",wurl, headers=wheaders, data=wpayload)
您好,我使用Python请求模块编写了这样一个程序。问题是,我可以先从程序的头部分获取身份验证代码,然后才能使用它。但是我不能从第二部分的数据中得到我想要的数据。错误代码如下所示
Traceback (most recent call last):
File "d:\requeststest\app.py", line 30, in <module>
getdata = wresponse.headers['Id']
File "C:\Users\Alp\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\structures.py", line 54, in __getitem__
return self._store[key.lower()][1]
KeyError: 'id'
虽然我在收到的数据中有ID信息,但当我试图获取ID信息时,会出现此错误。但是在第一个请求中,我能够以相同的方式从头部获取身份验证代码。你能帮忙吗
请求是对案件不敏感的指令
使用
get
方法从这个构造的dicts中获取项要好得多但是,您的错误是
Id
键不存在。 尝试使用wresponse.headers.keys()
或print(wresponse.headers)
并验证祝你好运
相关问题 更多 >
编程相关推荐