python+request+pytest对同一个地址发起options、post请求,cookie保存在post响应...
python+request+pytest对同一个地址发起options、post请求,cookie保存在post响应头Authorization中,如何获取?@pytest.mark.parametrize('url,headers', [('https://***', headers)])
def test_login(self, url, headers):
url = url
headers = headers
res = requests.options(url=url, headers=headers)
# print('\n**********\n',res.headers['Allow'])
assert res.status_code == 204
@pytest.mark.parametrize('url,data,headers', [
('https://***', {'mobile': '***',
'password': '1234567'},
headers)
])
def test_getseesion(self, url, data, headers):
url = url
data = data
headers = headers
res = requests.post(url=url, data=data, headers=headers)
hd = res.headers
print('\n***********\n', hd, '\n***********\n')
assert res.status_code == 200
def test_logout(self):
token = ''
print(token)结果打印的hd中不包含Authorization,我们的session是保存在cookie里的,如何获取?
https://blog.csdn.net/weixin_39597399/article/details/110986759参考下这个看看 response.request._cookies 响应对应请求的cookie;返回cookieJar类型 设置请求头就好了啊 参考下这个链接https://blog.csdn.net/xc_zhou/article/details/81021496 保存就行
页:
[1]