S
S
seropaski2017-05-19 17:09:30
Python
seropaski, 2017-05-19 17:09:30

[requests] How to get rid of duplicate cookies?

Library used: requests
Creating a session: Making session = requests.Session()
some requests. I save cookies to a file like this:

pickle.dumps(requests.utils.dict_from_cookiejar(session.cookies))

In another script, I also create a session, load from a cookie file like this:
cookies = requests.utils.cookiejar_from_dict(pickle.loads(DATA_FROM_FILE))
and I set their sessions: session.cookies = cookies
After I make several requests, a miracle happens. If the response to the request contains a Set-Cookie and the key already exists, then it is added again. Calculate the reason. Those cookies that I load from the file do not belong to the domain, and those that come from Set-Cookie belong to the domain to which the request is made.
How to get rid of duplicate cookies? Maybe somehow you can save cookies with belonging to the domain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2017-05-19
@dimonchik2013

pyCurl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question