Skip to main content
  1. Posts/

Using Proxy in Python Requests package

··154 words·1 min·
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
How to Download Files from Google Cloud Storage in the Databricks Workspace Notebook
··551 words·3 mins
Databricks Cli Usage
·141 words·1 min