Proxy Works in a Browser but Fails in Code
The proxy loads pages in your browser, but the same proxy fails or behaves oddly from a Python script, curl or a Playwright test. Often the proxy is fine and a setting differs between clients. This checklist finds that setting by changing one thing at a time.
Quick Answer
Keep the destination, proxy endpoint and credentials fixed, then send the same request four ways: direct, curl, Python Requests and Playwright. The first client that disagrees points at the cause. The usual causes are four settings: the proxy URL scheme or dict keys, credentials that need percent-encoding, an environment variable that overrides your code, or where DNS is resolved.
- →curl works, Requests fails: check
HTTPS_PROXY, thehttpskey and encoding - →Requests works, Playwright fails: pass username and password as separate fields over HTTP
- →Every client reaches an echo endpoint: the target is rejecting the client, not the proxy
1. Hold three things constant
A comparison only means something when the inputs match. Before running any test, write down:
- •The destination. Use a page you control or a neutral one such as
https://example.com/, plus an IP echo such ashttps://api.ipify.org?format=json. Do not debug against the site that blocks you; that mixes two problems. - •The endpoint. One host, one port, one protocol (HTTP or SOCKS5). Check what the browser actually uses: a proxy extension, a system setting or a PAC file may point it at a different port, or at no proxy at all. Open the echo page in that browser and note the IP it shows.
- •The credentials. The same username and password, loaded the same way in every client. A copy-paste error or a trailing space is enough to produce a 407.
The examples below read credentials from environment variables to keep them out of the code and out of any output. The Requests documentation warns that storing credentials in environment variables or version-controlled files is a risk, so in production load them from a secret manager. Never print the proxy URL in logs. If you have not yet confirmed the proxy itself works, start with how to test a proxy.
2. Send the same request four ways
Set the variables once in your shell. The host below is a documentation address; replace it with the one issued for your proxy. TLS verification stays on in every example.
# example values: replace with your own, never commit them
export PROXY_HOST="192.0.2.10"
export PROXY_PORT="8000"
export PROXY_USER="your-username"
export PROXY_PASS="your-password"
# 1) direct, no proxy
curl -sS -o /dev/null -w "%{http_code}\n" https://example.com/
# 2) curl through the proxy (-U avoids URL-encoding problems)
curl -sS -o /dev/null -w "%{http_code}\n" \
-x "http://$PROXY_HOST:$PROXY_PORT" -U "$PROXY_USER:$PROXY_PASS" \
https://example.com/Python Requests, with the environment switched off so only the code decides the route:
import os
from urllib.parse import quote
import requests
user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASS"], safe="")
proxy = f"http://{user}:{password}@{os.environ['PROXY_HOST']}:{os.environ['PROXY_PORT']}"
session = requests.Session()
session.trust_env = False # ignore proxy environment variables for this test
r = session.get("https://example.com/", proxies={"http": proxy, "https": proxy}, timeout=20)
print(r.status_code)Playwright (Node.js), with credentials in their own fields:
import { chromium } from "playwright";
const { PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS } = process.env;
const browser = await chromium.launch({
proxy: { server: "http://" + PROXY_HOST + ":" + PROXY_PORT, username: PROXY_USER, password: PROXY_PASS },
});
const page = await browser.newPage();
const res = await page.goto("https://example.com/", { timeout: 30000 });
console.log(res.status());
await browser.close();Each of these prints 200 when the path works. A status code alone does not prove the request went through the proxy, though. Repeat each test against the IP echo and compare the address with your own. Example of the shape to expect:
# example output (documentation addresses, not a real result)
direct: {"ip":"198.51.100.7"} <- your own connection
curl: {"ip":"203.0.113.24"} <- proxy exit
requests: {"ip":"203.0.113.24"} <- proxy exit
playwright: {"ip":"203.0.113.24"} <- proxy exitIf one client shows your own address, it bypassed the proxy. Full setup for each client lives in its own guide: curl, Requests with SOCKS5 and Playwright proxy configuration.
3. Decision tree
Work down the list and stop at the first "no".
1. Does the direct request reach the target?
No: the problem is your network or the target, not the proxy. Fix that first.
2. Does the browser show the expected exit IP on the echo page?
No: the browser is not using the proxy you think it is. Find which endpoint it really uses, then test that one in code.
3. Does curl through the proxy return the proxy exit IP?
No: read the curl exit code. Exit 5 is a syntax problem in the proxy string (often an unencoded @ or colon), exit 7 means the host or port did not accept a connection, and exit 56 with a 407 response is authentication.
4. Does the Requests snippet above return the same exit IP?
No: check the scheme in the proxy URL, both dict keys, the requests[socks] extra if you use SOCKS, and credential encoding. Yes, but your application still fails: your application is configured differently. Look for HTTP_PROXY, HTTPS_PROXY, ALL_PROXY or NO_PROXY in its environment and for proxies set only on the session.
5. Does the Playwright snippet load the page?
No: make sure username and password are separate fields and the server is an HTTP endpoint. Playwright documents authentication for HTTP proxies, and in our run it refused SOCKS5 with credentials at launch.
6. Every client reaches the echo, but the target rejects the script?
The proxy path is fine. The target is answering that client. Go to section 6.
4. Comparison matrix: what each failure looks like
We ran these cases on 29 November 2026 against a small authenticated HTTP CONNECT proxy on our own machine (loopback), with https://example.com/ as the target. Versions: curl 8.7.1, Requests 2.32.5, Playwright 1.64.1 with Chromium. This was not a mobile proxy port; it isolates client behaviour. Passwords and hosts in the messages are redacted. Other versions, and real proxies that answer a bad password differently, may print different text.
| Client | Test | Observed (redacted) | What it means | Basis |
|---|---|---|---|---|
| curl | Direct, no proxy | 200 | Target reachable; baseline set | Reproduced |
| curl | -x http://HOST:PORT -U user:pass (password has @ and :) | 200 | Proxy and credentials are good | Reproduced |
| curl | Same password raw inside the -x URL | exit 5: Unsupported proxy syntax in 'http://user:[redacted]@PROXY_HOST:PORT': Port number was not a decimal number between 0 and 65535 | URL parsing, not the proxy | Reproduced |
| curl | Wrong password | exit 56: CONNECT tunnel failed, response 407 | Authentication | Reproduced |
| curl | HTTPS_PROXY set to a closed port, no -x | exit 7: Failed to connect to [dead-host] port 1 | An environment variable chose the route | Reproduced |
| curl | Same HTTPS_PROXY, plus -x with the good proxy | 200 | -x overrides the environment | Reproduced |
| Requests | Credentials encoded with quote(..., safe="") | 200 | Proxy works from Python | Reproduced |
| Requests | Raw @ and : in the password | 200 | Parsed in 2.32.5, unlike curl | Reproduced |
| Requests | Raw # in the password | InvalidURL: Failed to parse: http://user:[redacted]@PROXY_HOST:PORT | Encode credentials | Reproduced |
| Requests | proxies has only an "http" key, target is https | 200, and the proxy log shows no CONNECT | Silent direct connection | Reproduced |
| Requests | Wrong password | ProxyError: ... Tunnel connection failed: 407 Proxy Authentication Required | Authentication | Reproduced |
| Requests | Proxy URL without a scheme | InvalidProxyURL: Please check proxy URL. It is malformed and could be missing the host. | Add http:// or socks5h:// | Reproduced |
| Requests | session.proxies set, HTTPS_PROXY points to a closed port | ProxyError: ... Unable to connect to proxy | Environment won over session.proxies | Reproduced |
| Requests | Same, proxy passed on the request instead | 200 | Per-request proxies win | Reproduced |
| Requests | Same, session.trust_env = False | 200 | Environment ignored | Reproduced |
| Requests | socks5h:// URL without requests[socks] | InvalidSchema: Missing dependencies for SOCKS support. | Install the extra | Reproduced |
| Playwright | launch proxy with server, username, password | 200 | Browser path works | Reproduced |
| Playwright | Same settings on newContext | 200 | Context-level proxy works | Reproduced |
| Playwright | Wrong password | page.goto: Timeout 15000ms exceeded | Auth fault shown as a timeout here | Reproduced |
| Playwright | Credentials embedded in the server URL | No Proxy-Authorization reached the proxy; goto timed out | Use the separate fields | Reproduced |
| Playwright | socks5:// server with username | browserType.launch: Browser does not support socks5 proxy authentication | Use the HTTP endpoint | Reproduced |
| Requests, curl | socks5:// compared with socks5h:// | Not run end to end | socks5 resolves DNS on the client, socks5h on the proxy | Documentation |
Two rows deserve attention. The Requests case with only an http key returned 200, which looks like success, yet the proxy never saw the request: it went out over the direct connection. And Playwright reported a wrong password as a navigation timeout, not as an authentication error, so a timeout in a browser test is worth checking against curl before you raise the timeout.
5. The four settings that usually differ
Scheme and dict keys
The Requests docs state that proxy URLs must include the scheme. In the proxies dict, the keys name the scheme of the destination URL, not of the proxy: {"https": "http://..."} means "send https:// requests through this HTTP proxy". Set both keys. In curl, a proxy string with no scheme or with http:// is treated as an HTTP proxy.
Credential encoding
curl URL-decodes the user and password inside the proxy string, so @ must be written %40 and a colon %3a. Passing credentials with -U sidesteps this; the curl manual adds that values on a command line can be briefly visible to other users of the same system. In Python,urllib.parse.quote(value, safe="") encodes every reserved character. Playwright needs no encoding because the credentials are not part of a URL.
Environment overrides
Requests reads http_proxy, https_proxy, no_proxy and all_proxy (and their uppercase forms) when you do not pass proxies on the request, and its docs warn that values set on session.proxies can be overwritten by them. Either pass proxies= on every call or set session.trust_env = False. curl reads the same family of variables (plain http_proxy only in lower case), and its -x option overrides them. curl also loads a default .curlrc file if one exists, so a proxy line there can change a command you thought was direct.
DNS resolution
With socks5://, Requests and curl resolve the hostname on your machine; with socks5h://, the proxy resolves it. A name that resolves differently from your network, or not at all, fails in one mode and works in the other. The details are covered in the Requests SOCKS5 guide and in DNS leaks with proxies.
6. Connection failure, target rejection or browser state
Sort the symptom into one of three buckets before changing code:
Connection failure
The echo test fails too: exit codes 5, 7 or 56, ProxyError, a 407, or a timeout. Work through sections 3 to 5.
Target rejection
The echo works from every client, but the target returns 403, 429 or a challenge page to the script.
Browser state
The browser carries cookies, a login, a passed challenge and its own TLS and header profile. A fresh script carries none of these.
For what each status code means and when to retry, use proxy error codes explained. If the browser is accepted and the script is not on the same IP, the difference is the client, and TLS fingerprinting (JA3 and JA4) and how websites detect proxies explain what the site may be comparing. Changing proxies will not fix a client mismatch.
Where our ports fit
Each mobileproxies.org port is one physical 4G/5G modem with its own SIM on a mobile carrier network, assigned to you alone for the rental, with HTTP and SOCKS5 access. That makes the checklist simple to follow: use the HTTP endpoint for Playwright with credentials, and either protocol for curl and Requests. Markets are the United States (T-Mobile), the United Kingdom (Three) and the Netherlands (Vodafone). The EUR 5 plan gives you 10 hours to run this whole comparison on your own code before choosing a 7-day or 30-day plan; plans do not auto-renew. See pricing for every option.
Frequently asked questions
Why does my proxy work in the browser but not in Python Requests?
Usually the two clients are not using the same settings. The browser may route through an extension, a system setting or a different port, while Requests may be reading HTTP_PROXY or HTTPS_PROXY from the environment, missing the https key in its proxies dict, or failing to parse a password with special characters. Run the same echo request from both and compare the exit IP before changing anything else.
Why does curl work but Requests does not with the same proxy?
The Requests documentation warns that values set on session.proxies can be overwritten by environment proxies. Other common causes are a proxies dict with only an http key (https targets then go direct), a proxy URL without a scheme, and a socks5 URL without the requests[socks] extra installed. Passing proxies on each request, or setting session.trust_env to False, removes the environment from the test.
Do I need to percent-encode special characters in a proxy password?
For curl, yes when the credentials sit inside the -x URL: curl URL-decodes them, so @ becomes %40 and a colon becomes %3a. Passing them with -U avoids that. In our Requests 2.32.5 run a raw @ and colon parsed, but a raw # failed with InvalidURL, so encode both parts with urllib.parse.quote(value, safe="") to be safe in every client.
Why does Playwright ignore the credentials in my proxy URL?
Playwright takes the proxy server, username and password as separate fields, and its documentation describes username and password for HTTP proxies. In our run, credentials embedded in the server URL were never sent to the proxy, and a socks5 server with a username failed at launch with "Browser does not support socks5 proxy authentication". Use the HTTP endpoint with separate fields.
How do I tell a proxy failure from a site rejecting my script?
Send the request to a neutral echo endpoint first. If every client gets the proxy exit IP back, the proxy path works and a 403 or challenge page from your real target is the site's answer to that client. Browser state such as cookies, a passed challenge or a different TLS fingerprint can explain why the browser is accepted while the script is not.
Sources & tools referenced
- • Requests - Advanced usage: proxies, environment variables, SOCKS
- • Requests - API reference (Session.trust_env, verify)
- • Playwright - Network: HTTP proxy, global and per-context
- • Playwright - BrowserType.launch proxy option (server, bypass, username, password)
- • curl - manual page (-x, -U, --noproxy, proxy environment variables, .curlrc)
- • Python - urllib.parse.quote
Related guides
Tutorial
How to Test a Proxy
Exit IP, ASN, header and leak checks
Tutorial
Playwright Proxy Configuration
Browser and context-level setup
Tutorial
Python Requests SOCKS5
socks5 vs socks5h, retries and sessions
Reference
Proxy Error Codes Explained
Decode 403, 407, 429 and 502
Technical
TLS Fingerprinting
Why a script differs from a browser
Tutorial
Mobile Proxy with curl
The full command-line reference
Run the comparison on a dedicated mobile port
Run the four-client comparison on the proxy you have now. If you need a compatible endpoint with HTTP and SOCKS5 on a real carrier modem, the EUR 5 plan gives you 10 hours to repeat it on your own code.