Created
December 19, 2012 00:05
-
-
Save cbare/4333273 to your computer and use it in GitHub Desktop.
Show how to follow redirects, including rePOSTing, with the python requests library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## follow redirects, including rePOSTing, with the requests library. | |
| ###################################################################### | |
| import requests | |
| ## authentication with no redirects | |
| ans = requests.post(url=endp_prod + "/session", data=json.dumps(d), headers=h) | |
| ## results in a successful login | |
| ans.status_code | |
| 201 | |
| ans.json | |
| {u'sessionToken': u'Z8T0JFdP88iol3l7XSjj0Q00'} | |
| ## POST requests will be turned into GETs, unless we set strict_mode to True | |
| requests.defaults.defaults['strict_mode'] = True | |
| ## do the POST, including the flag follow redirects | |
| ans = requests.post(url=endp_dev + "/session", data=json.dumps(d), headers=h, allow_redirects=True) | |
| ## yay! | |
| ans.status_code | |
| 201 | |
| ans.json | |
| {u'sessionToken': u'6cxGKVwTwxujxYFUUsmI1w00'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried requests.get(url, allow_redirects=True) but it is not working.