I am currently using a proxy when making get requests, via the requests
library in Python3. I have Tor and Privoxy set up for my proxies, and the code looks like:
import requests
proxies = {
"http": "http://127.0.0.1:8118",
"https": "https://127.0.0.1:8118"
}
resp = requests.get("https://icanhazip.com", proxies=proxies)
I am wondering if there is a way to look in resp
if the http or https proxy was used. Is there a way to do this?
I think that the most pythonic way is this:
import requests
from urllib.parse import urlparse
def get_scheme(url):
return urlparse(url).scheme
url = 'https://www.whatever.com'
response = requests.get(url)
scheme = get_scheme(response.url)
Alternatively, you could do:
import requests
url = 'https://www.whatever.com'
response = requests.get(url)
scheme = response.url.split(':')[0]