1

Directly from the python requests examples is this snippet:

payload = {'key1': 'value1', 'key2': 'value2'}  
r = requests.get("http://httpbin.org/get", params=payload)  
print r.url  
u'http://httpbin.org/get?key2=value2&key1=value1'

But when I try to pull data from a website (using requests 0.13.0):

payload = {'one' : 'one', 'two' : 'two' }  
r = requests.get("http://[ip_removed]/clubs/pairs_results/personal.php", params=payload)
print r.url  
http://[ip_removed]/clubs/pairs_results/

That's not correctly encoded at all. Ideas?

EDIT: Looks like the site issues a 302 redirect. How do I deal with that to get the same html that my browser will see.

2
  • Second code fragment works for me .... Try doing it with your local ip (127.0.0.1) and post the actual example? Commented May 30, 2012 at 11:22
  • Does your server redirect, perhaps? Commented May 30, 2012 at 11:46

1 Answer 1

4

The site simply does a HTTP 302-redirect here which requests follows, so you'll end up on a different url than originally requested. That's not error but the expected behaviour.

If you don't want that, you can add the allow_redirects=False keyword argument when sending the request.

And by the way: a google search with inurl:... quickly reveals which site you're talking about here, even if you remove the ip...

Sign up to request clarification or add additional context in comments.

2 Comments

So why when I encode the url manually and put it into a browser do I not get redirected? How do I get the same html my browser will get?
Don't know, maybe you need to set some cookies too? Use some inspection tool (like HttpFox) to find out what's actually being sent to the server.

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.