PacketStream integration
Using PacketStream residential proxies with Python Requests
Copy a Python Requests setup for PacketStream's HTTPS or SOCKS5 proxy, with timeouts, exit checks, country targeting, and sessions.
Add PacketStream to a Python script with the same Requests API you already use. The example sets an explicit timeout, rejects HTTP errors, and works with automatic rotation or a sticky session.
Configure
Install Requests, then read credentials from the environment:
python -m pip install requests
export PACKETSTREAM_USER='your_username'
export PACKETSTREAM_AUTH_KEY='your_auth_key'
import os
from urllib.parse import quote
import requests
username = quote(os.environ["PACKETSTREAM_USER"], safe="")
auth_key = quote(os.environ["PACKETSTREAM_AUTH_KEY"], safe="")
proxy = f"https://{username}:{auth_key}@proxy.packetstream.io:31111"
response = requests.get(
"https://ipinfo.io",
proxies={"http": proxy, "https": proxy},
timeout=30,
)
response.raise_for_status()
print(response.json())
Requests supports SOCKS5 through its optional dependency:
python -m pip install 'requests[socks]'
Use socks5h://proxy.packetstream.io:31113 in place of the HTTPS proxy URI so hostname resolution also goes through the proxy.
Verify your exit
Run the script and inspect the returned ip, country, and network fields. Keep raise_for_status() so an HTTP error does not look like a valid exit response.
Country targeting and sticky sessions
Apply the suffixes before URL-encoding the auth key:
routed_auth_key = quote(
f'{os.environ["PACKETSTREAM_AUTH_KEY"]}_country-US_session-catalog42',
safe="",
)
proxy = f"https://{username}:{routed_auth_key}@proxy.packetstream.io:31111"
Use the resulting proxy value in both entries of the proxies dictionary.
Troubleshooting
- Pass the
proxiesdictionary on the request so ambient proxy environment variables do not replace your intended configuration. - Percent-encode the username and full auth key before putting them in a proxy URL.
- Set a timeout and call
raise_for_status()before parsing the response.
See proxy troubleshooting for authentication, TLS, connection, and rotation checks.