Set-Cookie header sets cookie in response but not session
See original GitHub issueWhen requesting a resource that responds with a Set-Cookie
header, the response.cookies
returns a RequestsCookierJar
with the cookies set in the header, however, the session.cookies
returns an empty RequestsCookieJar
.
Expected Result
When requesting a resource that responds with the following headers: {'Content-Type': 'text/plain', 'set-cookie': 'foo=bar;'}
, the response.cookies
should include the foo=bar
cookie and the session.cookies
should include the foor=bar
cookie.
E.g. both should be <RequestsCookieJar[<Cookie foo=bar for />]>
Actual Result
When requesting a resource that responds with the following headers: {'Content-Type': 'text/plain', 'set-cookie': 'foo=bar;'}
, the response.cookies
does include the foo=bar
cookie but the session.cookies
remains empty.
response.cookies
yields <RequestsCookieJar[<Cookie foo=bar for />]>
session.cookies
yields <RequestsCookieJar[]>
Reproduction Steps
import requests
session = requests.Session()
response = session.get('http://www.blah.com/')
print(response.cookies)
print(session.cookies)
System Information
$ python -m requests.help
{
"chardet": {
"version": "3.0.4"
},
"cryptography": {
"version": ""
},
"idna": {
"version": "2.7"
},
"implementation": {
"name": "CPython",
"version": "3.6.5"
},
"platform": {
"release": "17.3.0",
"system": "Darwin"
},
"pyOpenSSL": {
"openssl_version": "",
"version": null
},
"requests": {
"version": "2.19.1"
},
"system_ssl": {
"version": "100020ff"
},
"urllib3": {
"version": "1.23"
},
"using_pyopenssl": false
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@Audace it’s the same process but performed in two separate places. Here for
Session
and here forResponse
.It would appear something on your mocked response isn’t populating what we’re expecting in
r.raw
. As I said above, since this doesn’t appear to be a defect in Requests but rather an issue in the mocking setup, we should probably move this to StackOverflow. That will avoid constantly pinging 1300 people watching the issue tracker for bugs in Requests. Feel free to ping the link here, or use thepython-requests
tag if you create a SO question. Thanks!@nateprewitt got it. No this isn’t performing network IO - it’s a mocked response. I added a
Content-Length
to no avail. That being said, why would there be a difference betweenresponse.cookies
andsession.cookies
? Is there a fundamental difference in the cookie extractor for these two jars?