DEV Community

Cover image for HTTP 407 Proxy Authentication Required: What the Gateway Refused
IPOasis
IPOasis

Posted on Edited on

HTTP 407 Proxy Authentication Required: What the Gateway Refused


HTTP 407 Proxy Authentication Required means the gateway received the request and refused it because the login was missing or wrong. The target site never saw the call. A script that prints 407 is talking to the proxy, and the next useful step is the username, the password, and the URL that carries both.

What a 407 from the gateway means

A 407 is the proxy's own refusal. The client opened a connection to the host and port in the proxy URL, the gateway answered, and that answer said the request is not signed in. On an HTTPS target the same refusal often shows up as Received HTTP code 407 from proxy after CONNECT, because the client asked for a tunnel and the gateway stopped before opening it.

The header next to that status is Proxy-Authenticate. It names the sign-in method the gateway accepts, usually Basic. The client is supposed to retry with Proxy-Authorization. requests builds that header from the user and password in the proxy URL, so a 407 after you already put a login in the string means the gateway did not accept that pair. A longer checklist of the same status, without the URL cases below, is in what a 407 from the proxy means.

Where the login breaks inside the URL

The login breaks when a character in the password is also a character in the URL. A proxy URL has the shape scheme://user:password@host:port. The last @ separates the login from the host. A password that already contains @ adds a second one, and the parser treats everything after the first @ as the host. The gateway then sees a user that does not exist, and it answers 407.

A colon inside the password does the same kind of damage one field earlier. The first : after the scheme separates the user from the password. A second : makes the password look like a port, and the host the client dials is no longer the one the dashboard printed.

import os
from urllib.parse import quote
import requests

user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASS"], safe="")
host = os.environ["PROXY_HOST"]  # host:port from the dashboard
proxy = f"http://{user}:{password}@{host}"

session = requests.Session()
session.trust_env = False
session.proxies = {"http": proxy, "https": proxy}

print(session.get("https://api.ipify.org", timeout=30).text)
Enter fullscreen mode Exit fullscreen mode

quote turns @ into %40 and : into %3A before the string is parsed, and safe="" keeps those characters encoded. The gateway decodes them back into the password it has on file. trust_env = False stops an HTTPS_PROXY value in the shell from replacing the URL you just built. Both dict keys carry the same string, because requests picks the key from the target URL. A missing https key sends the echo service out from your own address, and the printed IP is the office one rather than a 407.

A 407 from the site is a different reply

A 407 from the site is the origin saying it wants a login, and it arrives only after the gateway has already accepted you. The status code is the same number. The hop that sent it is not.

You can tell them apart by what else came back. A gateway 407 arrives with Proxy-Authenticate, and the byte counter on the proxy account barely moves, because the tunnel never opened. A site 407 arrives with WWW-Authenticate, the exit IP was already chosen, and the gigabytes for that response are on the bill. Changing the proxy password does nothing for the second one. That login belongs to the site.

Gateway 407 Site 407
Who sent it The proxy, before the tunnel The origin, after the tunnel
Header beside it Proxy-Authenticate WWW-Authenticate
What the byte counter does Stays near zero Counts the response
What you edit The proxy URL The site login

Check the exit before you change the password again

The exit check is one request to an echo service, through the gateway, before any catalog URL. A printed address in the country you set means the login landed and the tunnel opened. A 407 on that same call means the gateway still rejected the pair, so the password, the encoding, or the copied user is still wrong. An office IP on that same call means the request never reached the gateway.

You read the dashboard user again before you generate a new password. Country and session mode usually live in that username, so a rotating user and a sticky user are different strings on the same host. Pasting the sticky user into a variable that still holds the rotating one produces a login the gateway does not have. IPOasis sticky sessions on dynamic residential hold one exit IP for up to 120 minutes. When the window ends, the next request can leave from a different household IP. The 407 does not come from that window ending. A finished window returns a new exit address, and a bad login returns 407.

Where the gateway string comes from

The host, the port, the username, and the password come from the provider dashboard, already paired. IPOasis lists dynamic residential proxies from $0.78 per GB, with HTTP and SOCKS5 on the same balance. Unused gigabytes stay on the balance, so a failed sign-in and the one echo that follows it do not burn a monthly plan. You copy that pair, encode the password, run the echo once, and only then open the host you actually need.

FAQ

  • What does HTTP 407 Proxy Authentication Required mean?
    HTTP 407 means the proxy wants a login before it will forward the request. The gateway sends Proxy-Authenticate, and the client retries with Proxy-Authorization. Until that pair matches an account on the gateway, the target site does not see the call.

  • Why does the error mention CONNECT?
    CONNECT is how a client asks an HTTP proxy to open a tunnel to an HTTPS host. The gateway checks the login before it opens that tunnel. A rejected login comes back as 407 from the proxy after CONNECT, with the store still uncontacted.

  • Why does a password with @ cause 407?
    The @ in a proxy URL separates the login from the host. A password that contains @ adds a second separator, so the client sends the wrong user and the wrong host. Encoding the password first, so @ becomes %40, keeps the separator where the URL expects it.

  • How is a site 407 different?
    A site 407 comes from the origin after the proxy has already accepted the tunnel. It arrives with WWW-Authenticate instead of Proxy-Authenticate, and the proxy byte counter moves. The login to fix is the site account, not the proxy user.

  • Why did the echo print an office IP instead of 407?
    The request missed the gateway. A missing https key, or an HTTPS_PROXY value still set in the shell, sends the echo out from your own address. trust_env = False and the same gateway string on both dict keys put that call back on the proxy.

Top comments (0)