Anyone who know requests Python - Q: Am I doing it wrong?

imleaking

BANNED
Joined
Oct 11, 2022
Messages
16
Reaction score
6
Am I doing it wrong?
I found CSRF token on first get request and provide it in next post request and still saying CSRF token failed. I am using session on requests.
 
Are you using the same session, or a fresh session on each request? That could be it. Try configuring the browser to use existing profile on the subsequent requests.

Edit:

Something like this should work..

Code:
https://stackoverflow.com/a/67389309/1437261
 
As this is about requests, you need to have a persistent session for all your request transactions:

Code:
import requests

s = requests.Session()
resp_get = s.get(your_get_url, headers=your_get_headers)
resp_post = s.post(your_post_url, headers=your_post_headers, data=your_post_data)
 
Are you using the same session, or a fresh session on each request? That could be it. Try configuring the browser to use existing profile on the subsequent requests.

Edit:

Something like this should work..

Code:
https://stackoverflow.com/a/67389309/1437261

As this is about requests, you need to have a persistent session for all your request transactions:

Code:
import requests

s = requests.Session()
resp_get = s.get(your_get_url, headers=your_get_headers)
resp_post = s.post(your_post_url, headers=your_post_headers, data=your_post_data)

problem wasn’t that, I did not read well. Problem is in requests cookies
 
As this is about requests, you need to have a persistent session for all your request transactions:

Code:
import requests

s = requests.Session()
resp_get = s.get(your_get_url, headers=your_get_headers)
resp_post = s.post(your_post_url, headers=your_post_headers, data=your_post_data)
Oh lol I totally thought he was using selenium. But yeah, the same concept applies for requests as well.

problem wasn’t that, I did not read well. Problem is in requests cookies
and by using the same session, you also send the same cookies.. So, the same solution should work for your case.
 
Oh lol I totally thought he was using selenium. But yeah, the same concept applies for requests as well.


and by using the same session, you also send the same cookies.. So, the same solution should work for your case.
Yeah, but it says wrong cookies, I would need to figure that out. Thanks anyway
 
Can you share the exact error message?
Maybe there are some thing you need to populate in the POST data, separate from the Cookie header.
It says that cookies arw wrong or required from web browser
 
It says that cookies arw wrong or required from web browser
Can't get too much clues on that...
Stackoverflow and Youtube are your friends, but if you're still having issues I can try to help by PM if privacy is a concern.
 
Can't get too much clues on that...
Stackoverflow and Youtube are your friends, but if you're still having issues I can try to help by PM if privacy is a concern.
I would try figure it out myself, thanks
 
Can't get too much clues on that...
Stackoverflow and Youtube are your friends, but if you're still having issues I can try to help by PM if privacy is a concern.
Can you please PM me?
 
If you are getting a CSRF token failed error even after including the token in your POST request, you may be doing something wrong or there could be a problem with the server-side implementation. Double-check that you are using the correct token and check the server-side code for issues.
 
Paste your code into ChatGPT, it will say if there is something wrong with it. It’s not always perfect, but it wrote great requests script when I needed one.
 
udemy phyton tutorial videos will be more useful in terms of the right solution, good work
 
i actually figured out to first make GET request on site and collect token, save session and cookies and then make POST request, worked for me
 
Most likely the CSRF token is dynamically generated by JavaScript. You'll need to execute said JS and generate the token.
 
Back
Top