Use Python Requests’ proxies argument to send a request through a proxy. Supply the endpoint issued with your order, keep credentials outside the source file, and test a single request before adding a collection loop. The proxy URL describes your connection to the proxy; the destination URL describes the website you want to reach.
This guide covers a small, explicit HTTP-proxy configuration. For a broader diagnostic sequence, use the proxy connection checking guide.
Before you start: have the host, port, supported protocol and authentication details ready. The examples use environment variables so that the article contains no working credentials. The timeout values illustrate configuration; they are not provider limits or recommended values for every job.
The Requests proxy documentation shows a dictionary keyed by destination scheme. In this example, both HTTP and HTTPS destinations use the same HTTP proxy endpoint. An HTTPS destination does not mean that you should automatically change the proxy URL to https://.
import os
from urllib.parse import quote
import requests
host = os.environ["PROXY_HOST"]
port = int(os.environ["PROXY_PORT"])
user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASSWORD"], safe="")
proxy_url = f"http://{user}:{password}@{host}:{port}"
proxies = {"http": proxy_url, "https": proxy_url}
response = requests.get(
"https://api.ipify.org?format=json",
proxies=proxies,
timeout=(10, 30),
)
response.raise_for_status()
print(response.json()["ip"])
Run this only when you are comfortable sending your connection’s public IP to ipify. You can substitute an HTTPS endpoint you control. The first value is a connection timeout and the second is a read timeout. Requests does not make this tuple a total wall-clock deadline for the complete operation.
Encoding the username and password separately prevents characters such as @ from accidentally becoming URL delimiters. Keep the unencoded credentials in your environment. Do not print proxy_url, paste it into a public issue, or commit it to a repository.
Make the same IP request without the proxies argument, in a separate process without proxy-related environment variables. Record the two results privately. A changed address is evidence about that request’s observed exit address; it is not proof that every application on your computer uses the proxy.
Next, request a page you own or are permitted to access. Keep the endpoint and credentials unchanged. This separates a connection problem from a response specific to one destination. If ipify works but your target does not, buying another package is not the first diagnostic step: capture the status or exception and identify the component that answered.
For a short sequence, keep the proxy configuration explicit at each call. This makes the example easier to inspect and avoids assuming that a session-level setting has precedence over every environment setting.
with requests.Session() as session:
response = session.get(
"https://example.com/",
proxies=proxies,
timeout=(10, 30),
)
response.raise_for_status()
print(response.status_code)
A Session is useful for related requests, but cookies, headers and authentication deserve separate consideration. Proxy credentials authenticate to the proxy. They are not a replacement for the target website’s account credentials or permission to collect its data.
Requests documents SOCKS support as an optional dependency, installed with python -m pip install 'requests[socks]'. Its proxy URL scheme also controls DNS handling: socks5:// resolves names on the client, while socks5h:// resolves them through the proxy. Confirm that both the endpoint and your installed client support the configuration you choose.
Use the SOCKS4 versus SOCKS5 guide for protocol context. A protocol’s capabilities do not establish which features a commercial endpoint provides.
Catch exceptions where your program can make a meaningful decision. A timeout means the operation exceeded a configured waiting period. A ProxyError needs its underlying cause examined. An HTTP error requires the response status and context. These observations call for different fixes.
Use the Requests Quickstart as the exception reference. Keep a sanitized record of the time, destination hostname, configured scheme and error type. Exclude passwords, authorization headers and full URLs containing secrets.
No. The example configures requests made by this Python call. A separate browser or application needs its own supported configuration.
Do not turn off verification as a routine fix. Compare the error with the certificate and network requirements documented for your environment. Diagnose the cause before changing trust settings.
Open the Proxyca bot, choose a plan and an available country, then use the connection details issued with your order. Keep those details private. Open Proxyca in Telegram.