Integrations
Use the proxy from Python
Rotating and sticky requests with requests and httpx, and the socks5h setup that keeps DNS lookups from leaking outside the proxy.
Every example below uses the same credential (mlabs_a1f9c3 / <PASSWORD>)
against the standard gateway (proxy.masklabs.io:8080 HTTP,
:1080 SOCKS5). Swap in your own username and password from the dashboard.
requests
pip install requests
Rotating, over HTTP, a fresh exit IP on every request, no suffix needed:
import requests
PROXY = "http://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:8080"
resp = requests.get(
"https://ipinfo.io/json",
proxies={"http": PROXY, "https": PROXY},
)
print(resp.json())
requests routes both http and https targets through the same proxy URL
, the scheme in the proxies dict keys is the target's scheme, not the
proxy's.
Sticky, append _sticky to the username, same password:
PROXY = "http://mlabs_a1f9c3_sticky:<PASSWORD>@proxy.masklabs.io:8080"
SOCKS5 (socks5h), requires the socks extra:
pip install "requests[socks]"
PROXY = "socks5h://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:1080"
resp = requests.get(
"https://ipinfo.io/json",
proxies={"http": PROXY, "https": PROXY},
)
Use socks5h, not socks5, the trailing h makes DNS resolution happen
through the proxy (at the exit location) instead of locally.
httpx
pip install httpx
# SOCKS5 support:
pip install "httpx[socks]"
Modern httpx takes a single proxy= argument on the client (older code you
may see elsewhere uses a proxies= dict, either the client wide proxy= or
per-mount proxies= still works, but proxy= is the simplest for a single
upstream like ours):
import httpx
PROXY = "http://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:8080"
with httpx.Client(proxy=PROXY) as client:
resp = client.get("https://ipinfo.io/json")
print(resp.json())
Sticky, pinned to a location, over SOCKS5:
PROXY = "socks5h://mlabs_a1f9c3_loc_ORD_sticky:<PASSWORD>@proxy.masklabs.io:1080"
with httpx.Client(proxy=PROXY) as client:
resp = client.get("https://ipinfo.io/json")
print(resp.json())
The async client works the same way, httpx.AsyncClient(proxy=PROXY),
if your scraper is already asyncio-based.
Picking a mode per job
Rotating is the right default for bulk page fetches; reach for _sticky only
when the target needs continuity across requests (a login, a paginated
search). See
Rotating vs sticky sessions and location targeting
for the full suffix grammar and the current location codes.