Python (Scripting) - Location Redirects
by
Jeremy Canfield |
Updated: April 01 2024
| Python (Scripting) articles
The requests module can be used to issue a REST API request.
For example, perhaps like this.
#!/usr/bin/python
import requests
response = requests.get("http://www.example.com/api")
print(response.text)
And let's say the response has something about a location redirect, perhaps the following.
You have reached this page by following a redirect Location header from an OAuth authorize request.
By default, Python follows location redirects. You can disable the location redirect using allow_redirects=False.
#!/usr/bin/python
import requests
response = requests.get(
"http://www.example.com/api",
allow_redirects=False
)
print(response.text)
Did you find this article helpful?
If so, consider buying me a coffee over at