Sales open soon. The prices below show what we plan to charge. The tools on this site already work.

407 Proxy Authentication Required: what it means and how to fix it

407 Proxy Authentication Required means the proxy itself refused the request: it wants a username and password, and it did not get them, or did not accept the ones it got. The site you were trying to open never saw the request.

Code 401 comes from a website and asks you to sign in to it. Code 407 comes from the proxy between you and the site. The proxy names the sign-in method it wants in the Proxy-Authenticate header, and the client answers with a Proxy-Authorization header. For an HTTPS site the login goes in the tunnel request (CONNECT), so the error often comes wrapped in another message: CONNECT tunnel failed, response 407 in cURL, Tunnel connection failed: 407 in Python and pip, E407 in npm.

The causes, most common first

CauseHow it looksFix
No username and password were sentOnly the host and port are setPut the login into the proxy URL, http://USERNAME:PASSWORD@host:port, or into the tool's proxy login fields.
Wrong username or passwordA typo, a space at the end, a password that was resetCopy both again from the dashboard. A reset password stops the old one at once, everywhere it was saved.
Special characters in the password, not encodedThe login is right, but only in the URL form it failsIn a URL, @, :, /, #, % and ? must be written as %40, %3A, %2F, %23, %25 and %3F. The URL generator does it for you.
Wrong options in the usernameThe plain username works, with options it does notCheck the option format: USERNAME-country-DE, a two-letter country code, options separated by -, and no options in the password.
The proxy lets in only listed IP addressesIt worked yesterday, today your address changedSome providers check your IP instead of a login. Add your new IP to the list, or switch to a username and password. Proxyron plans use a username and password.
The proxy wants another sign-in methodAn office proxy; the browser works, pip, npm or cURL do notOffice proxies often want NTLM or Kerberos, which pip and npm cannot do. More in Behind an office proxy below.
An old proxy setting is still onThe error appears in a program you did not set upHTTP_PROXY and HTTPS_PROXY variables, .npmrc, pip.conf or the system proxy still hold an old address or login.

Check the login first

Paste the proxy into the proxy checker. It says plainly whether the proxy refuses the login, does not answer or works, and shows the exit IP. If the checker accepts the login, the proxy is fine and the problem is in how your program sends it: find your tool below. In the examples, put your proxy's host, port, username and password in place of gate.example.com, 8080, USERNAME and PASSWORD.

cURL

cURL prints curl: (56) CONNECT tunnel failed, response 407 for an HTTPS site and shows the page with code 407 for an HTTP one. Give the login separately with -U, so special characters need no encoding (all proxy options: the cURL guide):

curl -v -x http://gate.example.com:8080 -U "USERNAME:PASSWORD" https://proxyron.com/api/tools/myip

In Windows PowerShell, type curl.exe instead of curl: there curl is another command and does not know these options. With -v, look at the lines after CONNECT: Proxy-Authorization: Basic must be among the lines cURL sent. If it is missing, cURL did not get the login. If it is there and the answer is still 407, the login is wrong. If the answer has Proxy-Authenticate: NTLM or Negotiate, add --proxy-ntlm or --proxy-negotiate, or --proxy-anyauth to let cURL pick. Also check that http_proxy and https_proxy in your shell do not point at another proxy: env | grep -i proxy.

Python requests

The error reads ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 407 Proxy Authentication Required')). Put the login into the proxy URL and encode the password:

from urllib.parse import quote
import requests

user = "USERNAME"
password = quote("PASSWORD", safe="")
proxy = f"http://{user}:{password}@gate.example.com:8080"
proxies = {"http": proxy, "https": proxy}

print(requests.get("https://proxyron.com/api/tools/myip", proxies=proxies, timeout=30).text)
  • Both keys, http and https, take the same http:// address: the key is the scheme of the site, not of the proxy. Without the https key, HTTPS requests skip your proxy and may hit another one from the environment.
  • requests also reads HTTP_PROXY and HTTPS_PROXY. An old value there brings the 407 back; a Session with trust_env = False ignores them.
  • Code samples for Python, Node.js and other languages with the login in place: the code generator.

pip

pip shows ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')) and retries. Pass the proxy with the login:

pip install --proxy http://USERNAME:PASSWORD@gate.example.com:8080 requests

Encode special characters in the password, as in the table above. If you did not pass --proxy, pip took the proxy from HTTPS_PROXY or from proxy = in pip.conf (pip.ini on Windows): pip config list shows it. pip can send only a plain username and password, so behind an office proxy that wants NTLM it fails whatever you type.

npm

npm stops with npm error code E407, older versions with npm ERR! code E407 or tunneling socket could not be established, statusCode=407. npm keeps the proxy in its config, separately for HTTP and HTTPS:

npm config set proxy http://USERNAME:PASSWORD@gate.example.com:8080
npm config set https-proxy http://USERNAME:PASSWORD@gate.example.com:8080

npm config get https-proxy shows what npm uses now. An old login often sits in .npmrc in your home folder or in the project; npm config delete proxy and npm config delete https-proxy remove it. pnpm and Yarn 1 read the same settings; Yarn 2 and later take httpProxy and httpsProxy from .yarnrc.yml.

Chrome and Edge

The browser does not show 407 as an error page: it asks for the proxy username and password in a dialog. If the dialog keeps coming back, the login is wrong. If you closed it, the page ends with ERR_TUNNEL_CONNECTION_FAILED or stays blank, and the browser does not ask again until every window is closed. Close the browser fully, open it and enter the login again. Chrome cannot send a login to a SOCKS5 proxy, so use the HTTP port 8080. Step by step: the Chrome guide.

Postman

Postman shows Error: tunneling socket could not be established, statusCode=407 when it uses a proxy without a login. Open Settings → Proxy, turn on Use custom proxy configuration, enter the host and port 8080, then turn on Proxy auth and enter the username and password. Here they go in separate fields, so do not encode them. If Use system proxy is on, Postman takes the proxy from the system settings and the HTTP_PROXY variables instead: check that they hold the right address and login.

Behind an office proxy

When the browser works and the command line gets 407, the office proxy usually signs you in with your Windows account (NTLM or Kerberos). The browser does this on its own; pip, npm and most libraries cannot. Ask the administrator for an address that takes a plain username and password, or run a small local proxy, such as px or Cntlm, that signs in to the office proxy for you, and point your tools at http://127.0.0.1 with its port.

When it works

Open My IP through the proxy, or call https://proxyron.com/api/tools/myip from your script. The address should be the proxy's exit, not yours, and its country the one in the username.

Proxies by country

Once the proxy is set up, check that the exit IP is in the country you need. Each guide gives the username option for it.

All 25 country guides