requests
requests copied to clipboard
RequestsCookieJar._find_on_duplicates wrongly fails on cookie with empty value
Getting the value of a cookie which is set without a value by a website raises a KeyError. I don't know if this is by design. Browsers seem to accept these kind of cookies, even though this behaviour seems like bad practice.
Expected Result
An empty string.
Actual Result
RequestsCookieJar._find_no_duplicates raises a KeyError
Reproduction Steps
In ipython:
import requests
resp = requests.get("https://www.pib-insurance.com/")
resp.cookies.get_dict() # pretty print cookies
resp.cookies["firstname"]
Fix
I think last if in _find_no_duplicates (line 397 of cookies.py) should be if toReturn is not None: to accommodate for cookies without values.
Thanks!
Mark,the same problem
Mark, the same problem