When I try to make a request using http://
some websites perform a redirection and I find the final destination starting with https://
.
How can I make my request only support http://
and not accept https://
?
For example, this code:
import requests
requests.packages.urllib3.disable_warnings() # to disable warnings
response = requests.get("http://facebook.com",verify=False,timeout=5)
responseURL = response.url
print(responseURL)
Will provide this result:
https://www.facebook.com/
What if I want to use http://
only?
You can easily do this using the allow_redirects
argument when sending the request.
Like this:
import requests
requests.packages.urllib3.disable_warnings() # to disable warnings
response = requests.get("http://facebook.com",allow_redirects=False, verify=False,timeout=5)
responseURL = response.url
print(responseURL)
Hope this helps!