Welcome to the MMOLEARN.COM

Build your first Dropshipping, Online Course, Affiliate, Blog, Business, Optin, etc, WEBSITE and make money with us. We offer over 10.000+ Wordpress Plugins & Themes which will let you build ANYTHING. Plus we have nice community which likes to gossip about building websites and making some money online! Its really easy to do when we have everything you need to BUILD anything you WANT. Hope you enjoy your stay and have a beautiful day with us!

or Register
gifd

MMO P&S Anyone know about Python requests? Am I doing this wrong?

LocalSk8r

Well-known member

VIP MEMBER
Reputation: 23%
Joined
May 18, 2016
Messages
119
Reaction score
60
Points
47
Is there an error in my approach? I've identified the CSRF token in the initial GET request and supplied it in the subsequent POST request, yet I still encounter a "CSRF token failed" message. I'm employing sessions in my requests.
 

Excunian

Well-known member

Reputation: 31%
Joined
May 13, 2017
Messages
208
Reaction score
53
Points
46
Are you using the same session or starting a new one each time? That could be the issue. Try setting the browser to use the same profile for the next requests.

Edit:

This might work...

Here's the code :
 

Runnish

Well-known member

Reputation: 31%
Joined
Aug 8, 2020
Messages
219
Reaction score
39
Points
52
Since this is about requests, you need to keep the session active for all your transactions.
import requests

# Create a session to keep requests active
s = requests.Session()

# Send a GET request
response_get = s.get(your_get_url, headers=your_get_headers)

# Send a POST request
response_post = s.post(your_post_url, headers=your_post_headers, data=your_post_data)
 

LocalSk8r

Well-known member

VIP MEMBER
Reputation: 23%
Joined
May 18, 2016
Messages
119
Reaction score
60
Points
47
Are you using the same session or starting a new one each time? That could be the issue. Try setting the browser to use the same profile for the next requests.

Edit:

This might work...

Since this is about requests, you need to keep the session active for all your transactions.
import requests

# Create a session to keep requests active
s = requests.Session()

# Send a GET request
response_get = s.get(your_get_url, headers=your_get_headers)

# Send a POST request
response_post = s.post(your_post_url, headers=your_post_headers, data=your_post_data)

The problem wasn't that—I didn't read carefully. The issue is with the cookies in the requests.
 

Excunian

Well-known member

Reputation: 31%
Joined
May 13, 2017
Messages
208
Reaction score
53
Points
46
Since this is about requests, you need to keep the session active for all your transactions.

import requests

# Create a session to keep requests active
s = requests.Session()

# Send a GET request
response_get = s.get(your_get_url, headers=your_get_headers)

# Send a POST request
response_post = s.post(your_post_url, headers=your_post_headers, data=your_post_data)

Oh, haha, I totally thought he was using Selenium. But yeah, the same idea works for requests too.

The problem wasn't that—I didn't read carefully. The issue is with the cookies in the requests.

By using the same session, you also keep the same cookies. So, the same solution should work for you.
 

LocalSk8r

Well-known member

VIP MEMBER
Reputation: 23%
Joined
May 18, 2016
Messages
119
Reaction score
60
Points
47
Oh, haha, I totally thought he was using Selenium. But yeah, the same idea works for requests too.



By using the same session, you also keep the same cookies. So, the same solution should work for you.

Yeah, but it says the cookies are wrong. I’ll need to figure that out. Thanks anyway!
 
Top Bottom