Skip to main content
  1. Posts/

Using Proxy in Python Requests package

··154 words·1 min·
Note Requests
Table of Contents

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

Refs
#

Related

How to Merge PDF Files
·167 words·1 min
Note PDF
Liveness and Readiness Check in Kubernetes
·213 words·1 min
Note Kubernetes GCP
Notes on Using GCP Logging
·345 words·2 mins
Note GCP Logging Regex