proxy-password-special-characters

proxy-password-special-characters: write a proxy URL when the password has @ : # or !

If your proxy username or password contains characters such as @, :, #, /, ?, % or a space, percent-encode them before you put the login into a proxy URL: @ becomes %40, : becomes %3A, # becomes %23. The other way out is to pass the login outside the URL, for example with curl’s -U 'USER:PASS' or Playwright’s separate username and password fields, where no encoding is needed. Without encoding, the tool splits the URL in the wrong place, reads part of the password as the host or port, or sends half a password, and you get errors such as curl’s “Unsupported proxy syntax”, “could not resolve proxy” or 407 that look like a broken proxy. proxy_url.py does the encoding for you and prints ready-to-paste lines for curl, environment variables, Python requests and Playwright.

Proxy302 maintains this tool and sells these proxies: static residential (ISP) IPs from $0.50 per day, rotating residential traffic from $1.50/GB (prices). The tool works with any provider’s login.

Usage

git clone https://github.com/proxy302/proxy-password-special-characters
cd proxy-password-special-characters
python3 proxy_url.py --from 'HOST:PORT:USER:PASS'                  # colon format from a dashboard
python3 proxy_url.py --from 'HOST:PORT:USER:PASS' --scheme socks5h
python3 proxy_url.py --host HOST --port PORT --user USER           # asks for the password, not echoed
python3 proxy_url.py --from 'HOST:PORT:USER:PASS' --test           # one request through an HTTP proxy
python3 proxy_url.py --check 'http://USER:PASS@HOST:PORT'          # see how an existing URL is parsed

Python 3.8 or newer, standard library only. In the colon format everything after the third : is the password, so a password may contain colons. You can also set the password in the PROXY_PASS environment variable instead of typing it.

Example

For the login demo-user with the password p@ss:w0rd!#1 (host and port shown as HOST:PORT):

Proxy URL with the login percent-encoded:
  http://demo-user:p%40ss%3Aw0rd%21%231@HOST:PORT

curl, login inside the URL (quoted for the shell):
  curl -x http://demo-user:p%40ss%3Aw0rd%21%231@HOST:PORT https://api.ipify.org
curl, login passed separately with -U (no percent-encoding needed):
  curl -x http://HOST:PORT -U 'demo-user:p@ss:w0rd!#1' https://api.ipify.org

Environment variables (POSIX shell):
  export HTTPS_PROXY=http://demo-user:p%40ss%3Aw0rd%21%231@HOST:PORT
  export HTTP_PROXY=http://demo-user:p%40ss%3Aw0rd%21%231@HOST:PORT

Python requests:
  proxies = {'http': 'http://demo-user:p%40ss%3Aw0rd%21%231@HOST:PORT', 'https': 'http://demo-user:p%40ss%3Aw0rd%21%231@HOST:PORT'}

Playwright takes the login as separate fields, so no encoding there:
  proxy={"server": "http://HOST:PORT", "username": "demo-user", "password": "p@ss:w0rd!#1"}

Characters that were encoded: '!'->%21  '#'->%23  ':'->%3A  '@'->%40

We tested all of these forms against a local proxy whose password was p@ss:w0rd!#1: the encoded URL, the -U form and the environment variable all got through, and --test printed the exit IP. With the password left raw, curl 8.7 stopped with exit code 5 and “Unsupported proxy syntax … Port number was not a decimal number”: it had read part of the password as the port. A raw @ alone gave the same exit code with “Bad hostname”.

--check on the raw URL shows the damage:

How Python's urllib reads 'http://demo-user:p@ss:w0rd!#1@HOST:PORT':
  scheme   http
  host     ss
  port     invalid (Port could not be cast to integer value as 'w0rd!')
  username demo-user
  password p

Problems:
  - part of the URL was read as a path, query or fragment: an unencoded / ? or # in the login
  - no valid port: often an unencoded # / ? or @ cut the URL short
Other tools may split the same URL differently. Rebuild it with --from or --host.

Encoding table

Character Encoded Why it breaks a URL
@ %40 Marks the end of the login
: %3A Separates user from password, and host from port
# %23 Starts a fragment; everything after it is cut off
/ %2F Starts the path
? %3F Starts the query
% %25 Starts an escape itself
space %20 Not allowed in a URL
! $ & + %21 %24 %26 %2B Allowed by the URL rules, but some tools and shells mangle them

The script encodes everything except letters, digits and - . _ ~. That is always safe: the proxy receives the decoded, original password.

The shell is a second trap

Even a correctly encoded URL can be changed by the shell before the program sees it. Put proxy URLs in single quotes. In bash and zsh, ! inside double quotes can trigger history expansion, and $ starts a variable. If the password contains a single quote itself, the curl and export lines this tool prints are already quoted correctly for a POSIX shell.

FAQ

Do I have to encode the username too? Yes, by the same rule. Usernames that carry session or country settings often contain - or _, which are safe and stay as they are.

Does encoding change my password? No. The client decodes it before logging in, so the proxy sees exactly the password you were given.

Which tools take the login outside the URL? curl (-U / --proxy-user), Playwright (proxy: {server, username, password}) and Puppeteer (page.authenticate()), among others. Where that option exists, it is the simplest fix.

Does --test work with SOCKS5? No. Python’s standard library has no SOCKS5 support, so the tool prints the curl command for you to run instead. For a step-by-step SOCKS5 check, see socks5-proxy-checker.

More proxy setup guides: proxy302.github.io/proxy-guides.

Facts checked 19 November 2026.