Verifying Proxy Usage in Python Requests

To Nha Notes | Aug. 27, 2024, 8:41 p.m.

When making HTTP requests through a proxy in Python using the requests library, it’s important to confirm that the requests are actually routed through the specified proxy. Here’s a simple way to do that.

First, configure your proxy:

import requests

url = "https://nekochan.vn"
proxy = {
    "https": "https://<PROXY_IP>:3128",
    "http": "http://<PROXY_IP>:3128",
}

response = requests.get(url, proxies=proxy)

After making the request, you can verify the proxy usage by checking the proxy_manager in the connection object:

print(response.connection.__dict__)
Look for the proxy_manager key in the output. If it shows your proxy's IP and port, your request was successfully routed through the proxy.

Check more on usage of urllib3 at https://urllib3.readthedocs.io/en/latest/advanced-usage.html#https-proxy-error-http-proxy',