本帖最后由 nqzva 于 2023-3-7 23:59 编辑
在header里设cookie是无效的
[CSS] 纯文本查看 复制代码
>>> cookies = { 'cook2':'test2','foo':'bar' }
>>> headers={ 'Cookie':'cook2=test2; foo=bar' }
>>> r1 = requests.get(url, headers=headers )
>>> r1.request.headers
{'User-Agent': 'python-requests/2.27.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}
>>> r2 = requests.get(url, cookies= cookies )
>>> r2.request.headers
{'User-Agent': 'python-requests/2.27.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Cookie': 'cook2=test2; foo=bar'}
原因具体分析源码吧 https://github.com/psf/requests/blob/main/requests/models.py |