3

Using Proxy in Python Requests package

 3 years ago
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.
neoserver,ios ssh client

Using Proxy in Python Requests package

2021-02-07146 words 1 min read 61 times read

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

Author jdhao

LastMod 2021-02-07

License CC BY-NC-ND 4.0

Reward
记录我的 2020

How to Get or Set Clipboard Text in Python


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK