If we need to access the internet via a proxy server, we should set proxy properly when making HTTP/HTTPS requests using the Requests package.
Here is a simple code sample:
import requests
proxy = {'http': "http://server_ip:port", 'https': "https://server_ip:port"}
r = requests.get(url, proxies=proxy)
In the above code, we set the proxy used for http and https requests. However, when I run the above code, I see the following error:
(Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’),))
To temporarily disable SSL verification (note that this is dangerous for
production applications! Do this at your own risk!), we can add verify=False
to the requests method:
r = requests.get(url, proxies=proxy, verify=False)
You will see the following warnings:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings