Bootstrap FreeKB - Python (Scripting) - Location Redirects
Python (Scripting) - Location Redirects

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 1ef847 in the box below so that we can be sure you are a human.