Skip to content
Troubleshooting

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.

9 min read·Last updated: November 2026

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, the https key 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 as https://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 exit

If 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. 1. Does the direct request reach the target?

    No: the problem is your network or the target, not the proxy. Fix that first.

  2. 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. 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. 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. 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. 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.

ClientTestObserved (redacted)What it meansBasis
curlDirect, no proxy200Target reachable; baseline setReproduced
curl-x http://HOST:PORT -U user:pass (password has @ and :)200Proxy and credentials are goodReproduced
curlSame password raw inside the -x URLexit 5: Unsupported proxy syntax in 'http://user:[redacted]@PROXY_HOST:PORT': Port number was not a decimal number between 0 and 65535URL parsing, not the proxyReproduced
curlWrong passwordexit 56: CONNECT tunnel failed, response 407AuthenticationReproduced
curlHTTPS_PROXY set to a closed port, no -xexit 7: Failed to connect to [dead-host] port 1An environment variable chose the routeReproduced
curlSame HTTPS_PROXY, plus -x with the good proxy200-x overrides the environmentReproduced
RequestsCredentials encoded with quote(..., safe="")200Proxy works from PythonReproduced
RequestsRaw @ and : in the password200Parsed in 2.32.5, unlike curlReproduced
RequestsRaw # in the passwordInvalidURL: Failed to parse: http://user:[redacted]@PROXY_HOST:PORTEncode credentialsReproduced
Requestsproxies has only an "http" key, target is https200, and the proxy log shows no CONNECTSilent direct connectionReproduced
RequestsWrong passwordProxyError: ... Tunnel connection failed: 407 Proxy Authentication RequiredAuthenticationReproduced
RequestsProxy URL without a schemeInvalidProxyURL: Please check proxy URL. It is malformed and could be missing the host.Add http:// or socks5h://Reproduced
Requestssession.proxies set, HTTPS_PROXY points to a closed portProxyError: ... Unable to connect to proxyEnvironment won over session.proxiesReproduced
RequestsSame, proxy passed on the request instead200Per-request proxies winReproduced
RequestsSame, session.trust_env = False200Environment ignoredReproduced
Requestssocks5h:// URL without requests[socks]InvalidSchema: Missing dependencies for SOCKS support.Install the extraReproduced
Playwrightlaunch proxy with server, username, password200Browser path worksReproduced
PlaywrightSame settings on newContext200Context-level proxy worksReproduced
PlaywrightWrong passwordpage.goto: Timeout 15000ms exceededAuth fault shown as a timeout hereReproduced
PlaywrightCredentials embedded in the server URLNo Proxy-Authorization reached the proxy; goto timed outUse the separate fieldsReproduced
Playwrightsocks5:// server with usernamebrowserType.launch: Browser does not support socks5 proxy authenticationUse the HTTP endpointReproduced
Requests, curlsocks5:// compared with socks5h://Not run end to endsocks5 resolves DNS on the client, socks5h on the proxyDocumentation

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

Related guides

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.