requests icon indicating copy to clipboard operation
requests copied to clipboard

RequestsCookieJar._find_on_duplicates wrongly fails on cookie with empty value

Open alexpostolache opened this issue 4 years ago • 2 comments

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!

alexpostolache avatar Oct 05 '21 15:10 alexpostolache

Mark,the same problem

feilins avatar Dec 30 '21 15:12 feilins

Mark, the same problem

conhaifeng avatar Aug 31 '22 12:08 conhaifeng