Why are cookies not being returned in my RequestsCookieJar?
Why are cookies not being returned in my RequestsCookieJar?
I'm trying to use python to login to a local website and run some API tests. That means that when we do a POST to log in it should re-use the cookies the server sent so latter requests are correctly authenticated.
POST
However, despite the Set-Cookie header being returned the cookie jar is empty. As a newbie to Python I can't figure out what I am doing wrong.
Set-Cookie
>>> import requests
>>> session = requests.session()
>>> response = session.post("http://localhost:46551/login", 'Email':'dev', 'Password':'1234')
>>> print(response)
<Response [200]>
>>> print(response.cookies)
<RequestsCookieJar>
>>> response.headers
'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'Expires': '-1', 'Server': 'Microsoft-IIS/10.0', 'UnAuthenticatedUser': 'true', 'X-AspNet-Version': '4.0.30319', 'Set-Cookie': 'Fuze=SOME-VALUE-HERE; domain=localhost; expires=Wed, 12-Sep-2018 15:05:22 GMT; path=/; HttpOnly, profile=29; domain=localhost; path=/; HttpOnly', 'X-SourceFiles': '=?UTF-8?B?QzpcY29kZVx3b3JrXGNhcmVzdGFja1xDYXJlU3RhY2suVW5pZmllZC5tc2hhcGlyb1xDYXJlU3RhY2suQmFja2VuZFxDYXJlU3RhY2suV2ViXGxvZ2lu?=', 'X-Powered-By': 'ASP.NET', 'Date': 'Wed, 12 Sep 2018 14:29:22 GMT', 'Content-Length': '42'
>>> len(response.cookies)
0
The important cookie in that example is the Fuze cookie which has the session token. The expiration is correctly 30 minutes from the time of the request.
Fuze
Am I doing something wrong or is this application sending a weird cookie back that Python can't handle?
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.