Skip to content
Back to blog

407 Error Code: Meaning, Causes & How to Fix It

Table of contents

Key takeaways:

  • A 407 error means your proxy server rejected the connection because it is missing valid credentials or the provided authentication credentials are incorrect.
  • Fix it by verifying your proxy username and password, and making sure your code actually sends these details in the request header.
  • Always test proxy authentication on a small scale before deploying large scripts.

When your script connects to a website through a proxy server, you need to pass valid proxy authentication so it knows you have permission to use it.

If you fail to provide valid credentials, the proxy server will block your request, and the connection will fail immediately.

What is the HTTP 407 error code?

A 407 error occurs when a proxy server blocks your request because it needs valid login credentials, which stops your traffic from reaching the target website. When blocking the connection, the proxy sends back a Proxy-Authenticate response header telling you how to verify your identity.

You need to send a new request that includes a Proxy-Authorization header with the valid credentials. Once the proxy server verifies these details, you can then use the proxies successfully.

What causes a 407 Proxy Authentication error?

The error typically happens for three reasons:

  • Missing or incorrect authentication credentials: You forgot to include your username and password in the request header, or you made a typo.
  • Unwhitelisted IP address: Many proxy providers authenticate via IP address. If the device running your script is not on your allowed list, the proxy server blocks the request.
  • Unsupported authentication method: Your script uses a proxy authorization format the proxy does not accept, such as sending Basic auth when it expects Digest.

Keep in mind that some proxy providers also return a 407 error when your plan expires or you run out of traffic. Check your dashboard balance, and look for an error message or response header that explains the exact cause.

How to fix the 407 Proxy Authentication Required error

To fix a 407 Proxy Authentication Required error, you need to make sure your username and password are correct. If your provider uses IP-based proxy authentication, log into your dashboard and confirm your current device is on the whitelist.

Also check the proxy host, port, and protocol. A wrong host or port usually ends in a connection error rather than a 407. SOCKS5 proxies often use a separate port and reject bad credentials with their own error instead of an HTTP status code.

Fix HTTP 407 in Python requests

You can pass proxy credentials to the Python Requests library to achieve proxy authorization by embedding them directly into the proxy URL string within a dictionary:

import requests
from urllib.parse import quote
 
username = quote("USERNAME", safe="")
password = quote("PASSWORD", safe="")  # encodes @, #, /, % and other special characters
proxy = f"http://{username}:{password}@proxy.example.com:8080"
proxies = {"http": proxy, "https": proxy}
 
try:
    response = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=10)
    print(response.status_code, response.text)
except requests.exceptions.ProxyError as error:
    print(f"Proxy error: {error}")

For HTTPS websites, Requests reports a 407 as a ProxyError with the message Tunnel connection failed: 407 Proxy Authentication Required, so you won't get a response object with the 407 status code. For plain HTTP websites, response.status_code returns 407 instead.

If your password contains special characters, you must URL-encode them. The quote() function in the example above does this for you. Without it, Requests can misread the URL: a # or / makes the URL invalid, while a % sequence turns into a different password and ends in a 407 error.

Fix HTTP 407 with cURL

You can test proxy authentication from your terminal using cURL. Use the -x flag to specify the proxy address and port, and the -U flag to pass your username and password:

curl -v -x http://proxy.example.com:8080 -U "USERNAME:PASSWORD" https://httpbin.org/ip

Adding the -v flag enables verbose mode, printing out all HTTP headers so you can verify your credentials are being passed correctly. Lines starting with > show what curl sent, and lines starting with < show the response it received. If the credentials never reach the proxy, the output looks like this:

> CONNECT httpbin.org:443 HTTP/1.1
> Host: httpbin.org:443
> User-Agent: curl/8.15.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 407 Proxy Authentication Required
< Proxy-Authenticate: Basic realm="Proxy Authentication Required"
<
curl: (56) CONNECT tunnel failed, response 407

This request has no Proxy-Authorization line, so the proxy never received your credentials. A common cause is the lowercase -u flag, which sends them to the target website instead of the proxy. If the Proxy-Authorization line is there and you still get a 407, the proxy rejected your authentication credentials, so check them and your IP whitelist.

How to prevent HTTP 407 errors in web scraping

Before you start a large scraping job, run a quick connection test to make sure your credentials and IP settings are valid and correct.

To prevent 407 Proxy Authentication Required errors from interrupting your scrapers:

  • Use built-in framework features: Tools like Scrapy have native proxy middleware that handles proxy authentication headers automatically. You rarely need to build custom proxy authorization middleware from scratch.
  • Set credentials in browser automation: Tools like Playwright take the proxy username and password as separate fields in their proxy settings, so add them there, or the proxy server will reject the browser's requests.
  • Secure a static IP: If your scraper runs on a device with a dynamic IP address, a mid-scrape network change will break your whitelist status and trigger sudden 407 Proxy Authentication Required errors. Always whitelist a static IP.
  • Monitor authentication errors: Log 407 responses separately from other failed requests and pause the job when they repeat, because rotating to another proxy in the same pool won't fix wrong authentication credentials or an outdated IP whitelist.

Scrape without 407 errors using reliable proxies in 2026

Start scraping

Conclusion

A 407 error means the proxy server, not the target website, needs valid credentials before it forwards your request. In most cases, the fix is to check your authentication credentials, IP whitelist, and traffic balance, then confirm that your code actually sends the credentials.

Test proxy authentication with a quick Python or cURL request before every large scraping job, and stop the job when 407 errors repeat instead of rotating through your proxy pool.

FAQ

What is the difference between HTTP 401 and 407?

Unlike proxy authentication failures, a 401 status means the target website rejected your credentials. A 407 status means your proxy server blocked the request.

Does rotating proxies help fix HTTP 407 errors?

Usually, no. A 407 Proxy Authentication Required means your authentication details or IP whitelist settings are wrong, which will block you across all proxies in your pool. If a single node in your provider network is misconfigured, however, rotating to a new proxy might sometimes help get around the error.

Should I retry a request that returns HTTP 407?

Do not set up automatic retries for a 407 error. Unless you update your authentication credentials or fix your IP whitelist, the proxy will continue to reject every subsequent request.

Can a firewall or VPN cause a 407 error?

Yes. Many company networks send traffic through a firewall proxy that needs its own login, such as NTLM or Kerberos, and it returns a 407 Proxy Authentication Required error until your script provides valid credentials. A VPN can also cause a 407 error if you use IP whitelisting, because it changes the public IP address your proxy provider sees.

Learn more

Related articles