0

I am trying to do a get request and saving the cookies from that and using it for a post request. I tried that with this code:

s = requests.Session()
resp = s.get(url1)
resp2 = requests.post(url2, data=payload, headers=headers, cookies=s.cookies)

but I can't get this to work correctly. The post request won't have the same cookies as the get request.

Am I doing something wrong?

1 Answer 1

1

You are already using Session(), its whole purpose is to save you the hassle of handling cookies. It already stores the cookies obtained from the server and automatically sends/updates them in subsequent requests.

Here's how you should do it:

s = requests.Session()
resp = s.get(url1)
resp2 = s.post(url2, data=payload, headers=headers)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.