-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
I would like to be able to override the cookie policy used by a Session when making a request or when using a Session to prepare a request. However, overriding the cookie policy on the cookie jar of the Session or of the Request object has had no effect. This line of code explains why:
https://github.com/kennethreitz/requests/blob/master/requests/sessions.py#L377
The cookie jars of both the session and the request are merged into a newly constructed RequestsCookieJar, discarding the policies of both. I believe there should be a way to inject a non-default cookie policy at this point.
What I expected to be able to do, and what isn't working currently, is something like the following:
import requests
s = requests.Session()
s.cookies = requests.cookies.RequestsCookieJar(policy=MyCustomCookiePolicy())
s.get('http://httpbin.org/cookies/set?k2=v2&k1=v1') # Put some cookies in the jar
r = requests.Request('GET', 'http://httpbin.org/cookies')
pr = s.prepare_request(r) # Include certain cookies in the jar based on arbitrary rules
# Print the request data for debugging
s.send(pr)Metadata
Metadata
Assignees
Labels
No labels