disable proxy in python requests

Disable Proxy in Python Requests

If you are using Python requests library and want to disable proxy, you can do so using the proxies parameter in the requests.get(url, proxies=None) function. The default value for this parameter is None, which means that the requests library will use system proxies by default. Here's how you can disable proxy:


import requests

response = requests.get("https://www.example.com", proxies={})
  

In the above code, we have passed an empty dictionary as the value for the proxies parameter. This will disable proxy for the request.

Another Way to Disable Proxy

Another way to disable proxy is to set the environment variable HTTP_PROXY and HTTPS_PROXY to an empty string:


import os
import requests

os.environ["HTTP_PROXY"] = ""
os.environ["HTTPS_PROXY"] = ""

response = requests.get("https://www.example.com")
  

In the above code, we have set the environment variables to an empty string before making the request. This will override any system-wide proxy settings.