Using Proxy in Python Requests package
source link: https://jdhao.github.io/2021/02/07/python_requests_with_proxy/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using Proxy in Python Requests package
If we need to access the internet via a proxy server, we should set proxy properly when making HTTP 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 services. 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), we can add verify=False
to the requests method:
r = requests.get(url, proxies=proxy)
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK