为什么 Python 中的 http 登录响应中没有 session ID?
Why there's no session ID in http login response in Python?
我的服务器使用 cookie header 成功响应我的浏览器客户端。但是 Python 有问题。我没有看到任何带有 session ID 的 cookie header。
我的代码:
import requests
url = 'http://192.168.0.100/login'
values = {'email': 'dude@example.com',
'password': '2314'}
with requests.session() as s:
s.get(url)
r = s.post(url, data=values)
print(r.headers)`
您似乎在身份验证后在服务器上进行了重定向,但客户端没有获得任何 cookie header。尝试将重定向限制包含在请求中:
r = s.post(url, data=values, allow_redirects=False)
然后您通过以下方式访问任何 cookie header:
r.cookies['HEADER_NAME']
我的服务器使用 cookie header 成功响应我的浏览器客户端。但是 Python 有问题。我没有看到任何带有 session ID 的 cookie header。
我的代码:
import requests
url = 'http://192.168.0.100/login'
values = {'email': 'dude@example.com',
'password': '2314'}
with requests.session() as s:
s.get(url)
r = s.post(url, data=values)
print(r.headers)`
您似乎在身份验证后在服务器上进行了重定向,但客户端没有获得任何 cookie header。尝试将重定向限制包含在请求中:
r = s.post(url, data=values, allow_redirects=False)
然后您通过以下方式访问任何 cookie header:
r.cookies['HEADER_NAME']