How to Read a Proxy URL: Host, Port and Username

Published:

10 minute read

Acar Diveroli
Written by: Acar Diveroli
A proxy URL split into one row of modules: http, user, pass, proxy.example and 8000; a blue @ separates login from server

A proxy URL is built from five parts: the scheme, username, password, host and port. Tools expect them on a single line, in URL form. Separator characters divide the parts. So if the password contains an unencoded @ or #, the tool splits the URL in the wrong place and tries to connect to a different server. This post covers what each part does, how to choose the scheme, how to encode special characters, and how to write the same URL for curl, Python and environment variables.

The five parts of the URL

A proxy URL is a URL and is parsed by URL rules. A tool splits http://user:pass@pr.proxynet.io:8000 at its separators: :// ends the scheme, @ ends the credentials, the last : marks the port.

PartExampleWhat it does
SchemehttpTells the tool which protocol to speak with the proxy
UseruserIdentifies your account
PasswordpassAuthenticates the user
Hostpr.proxynet.ioThe proxy server to connect to
Port8000The entry point on that server

The credentials are optional. If you authenticate with an IP whitelist, the URL becomes http://pr.proxynet.io:8000. The port, however, should always be there. Without it the tool falls back to its own default: in our test, Requests tried port 80 for an http:// URL with no port.

The username and password are decoded before they are sent. With an HTTP proxy they turn into a Proxy-Authorization: Basic header, with SOCKS5 into a separate authentication step. The proxy never sees the URL itself.

Choosing the scheme

The scheme sets how you talk to the proxy, not the protocol of the target site. Even when the target is HTTPS, the URL usually starts with http://. The tool asks the proxy for a CONNECT tunnel and sets up TLS inside it.

SchemeConnection to the proxyWho resolves DNS
http://Plain HTTP, CONNECT tunnel for HTTPSProxy
https://TLS to the proxy itselfProxy
socks5://SOCKS5Your machine
socks5h://SOCKS5Proxy

Use https:// only for a proxy endpoint that speaks TLS. Point https:// at a plain HTTP port and the tool starts a TLS handshake that never gets an answer. In our test, Requests stopped with a read timeout and curl with code (28).

The only difference between socks5 and socks5h is DNS. Our SOCKS5 test server logged the incoming target. With socks5://, the name localhost was resolved on our machine and the server received the IPv6 address ::1. With socks5h://, the server received the name localhost. If you want the target resolved from the proxy's country, use socks5h://. The Proxynet SOCKS5 Proxy also carries UDP, but the tools in this post use TCP.

Special characters in the password

RFC 3986 allows only letters, digits and a limited set of symbols in the user information. Every other character is percent-encoded: a % sign followed by the character's two-digit hex value. An unencoded @ or # splits the URL in the wrong place.

CharacterEncodedIf left unencoded
@%40Read as the start of the host
#%23Everything after it drops out of the URL
/%2FRead as the start of the path
:%3ASeparates user from password
%%25Mixed up with the encoding marker
?%3FRead as the start of the query

Our test password was p@ss#w/rd:%1. Written unencoded, Python's urlsplit split the URL like this: host ss, the rest a fragment after #. curl returned Could not resolve proxy: ss, Requests a NameResolutionError. Both tools looked for the same wrong server.

In Python you encode with urllib.parse.quote, but its default is a trap. The function is built for URL paths, so it ships with safe="/" and leaves / as it is. In our test, quote(password) returned p%40ss%23w/rd%3A%251 and Requests raised InvalidURL: Failed to parse. Always pass safe="".

python
from urllib.parse import quote

password = "p@ss#w/rd:%1"
print(quote(password, safe=""))  # p%40ss%23w%2Frd%3A%251

The encoded password does not reach the proxy in encoded form. Our test proxy received the original password in the Proxy-Authorization header from both tools. If the username has special characters, the same rule applies to it.

The same URL in curl and Python

The URL is written the same way in both tools. The difference is the option to pass credentials outside the URL.

In curl the URL goes after -x. If you pass the password separately with --proxy-user, no encoding is needed: curl sends it as is. The curl docs warn that this argument may briefly show up in the process list. For more options, see using a proxy with cURL.

bash
# Password pass@123: the @ is written as %40
curl -x "http://user:pass%40123@pr.proxynet.io:8000" \
  https://httpbin.org/ip

# Password passed separately, no encoding needed
curl -x "http://pr.proxynet.io:8000" \
  --proxy-user "user:pass@123" \
  https://httpbin.org/ip

In Python, build the URL from encoded parts and give the same value to the http and https keys. Requests decodes the credentials in the URL before sending them.

python
from urllib.parse import quote

import requests

user = quote("user", safe="")
password = quote("p@ss#w/rd:%1", safe="")
proxy = f"http://{user}:{password}@pr.proxynet.io:8000"

r = requests.get(
    "https://httpbin.org/ip",
    proxies={"http": proxy, "https": proxy},
    timeout=15,
)
print(r.status_code, r.text)

Requests needs the scheme. In our test, a user:pass@host:port URL with credentials but no scheme raised InvalidProxyURL: Please check proxy URL. curl treats a URL without a scheme as an HTTP proxy and connected. To stay consistent, write the scheme everywhere. For sessions, retries and SOCKS setup, move on to using a proxy with Python Requests.

Environment variables

HTTP_PROXY and HTTPS_PROXY set the proxy without touching the code. The variable name refers to the target site's protocol, the scheme in the value to the proxy protocol. That is why the HTTPS_PROXY value usually starts with http:// too.

bash
export http_proxy="http://user:pass@pr.proxynet.io:8000"
export HTTPS_PROXY="http://user:pass@pr.proxynet.io:8000"
export NO_PROXY="localhost,127.0.0.1"

In PowerShell the same value is written as $env:HTTPS_PROXY = "http://user:pass@pr.proxynet.io:8000". A password with special characters is encoded here as well, because the value is still a URL.

The two tools read the variables differently:

  • curl recognizes http_proxy only in lowercase. It reads the others in both spellings.
  • Requests reads both lowercase and uppercase spellings. ALL_PROXY can also carry a SOCKS URL.
  • Windows does not distinguish case in variable names. In our test, HTTP_PROXY worked in curl as well.

NO_PROXY is a comma-separated list of addresses that should not go through the proxy. In our test, with NO_PROXY=localhost set, both tools sent the localhost request directly, skipping the proxy. Local services and internal network addresses belong on this list.

Troubleshooting

The error message usually tells you which part of the URL is broken. Every message below came up in our test.

MessageCauseFix
Could not resolve proxy: ss (curl 5)Unencoded @ or # in the passwordPercent-encode the password
NameResolutionError (Requests)Same causequote(password, safe="")
InvalidURL: Failed to parsequote() left / unencodedAdd safe=""
InvalidProxyURLNo scheme in a URL with credentialsPrefix it with http://
Timeout, curl (28)https:// on a plain HTTP portUse http://
Failed to connect to …:80Port missingAdd the port
407Wrong or wrongly encoded passwordCheck the credentials

If you get a 407, the URL was parsed correctly and the problem is in the credentials. The full checklist is in the HTTP 407 error post. If you see a server name you don't recognize, such as ss, the problem is inside the password.

How we tested

We ran the tests on December 1, 2026, on Windows 11. We used Python 3.13.17, Requests 2.34.2, urllib3 2.6.3, PySocks 1.7.1 and curl 8.22.0. We ran an HTTP proxy and a SOCKS5 server on 127.0.0.1. Both logged the incoming credentials and the target address type. The target was a plain HTTP local address. So the CONNECT tunnel and HTTPS targets were outside this test. In the examples we replaced the local address with pr.proxynet.io:8000.

The bottom line

Build the URL from its parts, encode the password with safe="" and always write the scheme and the port. With SOCKS5, use socks5h:// if you want the proxy to resolve DNS. Above all, if an error message shows a server name you don't recognize, look inside the password. Once the URL is ready, you can send your first request with Residential Proxy.

Sources

Frequently asked questions

Should a proxy URL start with http or https?

Usually http://. The scheme sets how you talk to the proxy, not the protocol of the target site. When you reach an HTTPS site through an http:// proxy, the tool opens a CONNECT tunnel and the encryption stays inside it. https:// is only right if the proxy endpoint itself speaks TLS. On a plain HTTP port, the connection times out.

How do I write an @ sign in a proxy password?

As %40. In the URL, the first @ marks the end of the credentials, so an @ in the password is read as the start of the host. In Python, urllib.parse.quote(password, safe="") does the conversion. In curl, passing the password separately with --proxy-user removes the need to encode. The same rule applies to #, /, : and %. The proxy receives the original password, not the encoded one.

What is the difference between socks5 and socks5h?

DNS resolution. With socks5://, your machine resolves the target name and an IP address goes to the proxy. With socks5h://, the proxy receives the name and resolves it itself. In the second case no DNS query leaves your network, and the target is resolved from the proxy's location. In our test the server received ::1 with socks5:// and the name localhost with socks5h://.

Why does the HTTPS_PROXY value start with http://?

The variable name and the value's scheme describe different things. The name HTTPS_PROXY says that requests to HTTPS sites will use this proxy. The http:// in the value tells the tool to speak plain HTTP with the proxy. HTTPS traffic then passes through a CONNECT tunnel opened over that connection. Don't write https:// in the value unless your proxy speaks TLS.

How do I write NO_PROXY?

As a comma-separated list, for example NO_PROXY="localhost,127.0.0.1". Requests to the listed addresses go directly, skipping the proxy. According to the curl docs, the list accepts domain names, IP addresses and network ranges in CIDR notation. Add local services and internal network addresses here. Otherwise those requests go to the proxy too and fail.

Is the port required in a proxy URL?

Yes, always write the port. Without it the tool picks its own default, and that default varies from tool to tool. In our test, Requests tried port 80 for an http:// URL with no port and the connection was refused. Append the port your provider gives you to the end of the URL, like :8000. If you use SOCKS5, also check that the port is the SOCKS port.

Ask ChatGPTAsk Claude