401 Unauthorized Error: the Site Asks You to Sign In
The request reached the site, but the site did not accept your sign-in credentials or did not receive them at all. The proxy username and password have nothing to do with it.
Updated · Prokso editorial team
- Code 401 comes from the site: the proxy let you through, but the site credentials failed
- Most often the access token or session has expired
- Make sure the code is 401, not 407, then get a new token
What the error means
The 401 code means authentication is required to access the resource, and the request has no valid credentials. According to the HTTP standard (RFC 9110), together with 401 the server sends a WWW-Authenticate header that specifies how exactly to authenticate.
The main thing is not to confuse 401 with 407. The 407 code is sent by the proxy when it did not accept the proxy username and password, and it comes with a Proxy-Authenticate header. The 401 code is sent by the site: the proxy has already let you through, and the request reached its destination.
Causes
- The token or session has expired. Access tokens live for a limited time; after that, the site or API answers 401.
- The API key was not sent or was sent in the wrong place. The key is in the wrong header, the header name has a typo, or there is an extra space.
- The Authorization header was lost during a redirect. Some libraries remove it when a redirect leads to another domain. Python requests, for example, does this.
- Proxy credentials were put into site credentials. The proxy username and password ended up in Authorization instead of the proxy settings.
- The site reset the session after the address changed. Some sites ask you to sign in again when requests from one session come from different IPs.
How to fix it
- Check who answered: if the code is 407, the question is about the proxy credentials, see the 407 page. If it is 401, look for the cause in the site sign-in credentials.
- Get a new token or sign in to the site account again.
- Check the header name and key format against the documentation of the API you use.
- Keep the proxy credentials in the program's proxy settings and the site credentials in the request headers. An example of the correct split is in the Python requests guide.
- If the site ties the session to the address, work within one session with a sticky IP: ports 10000-20000 keep one IP for 1 to 120 minutes.
How to check that it works
Run the same request without the proxy with the same sign-in credentials. If you also get 401 without the proxy, the problem is in the token or key. If everything works without the proxy, compare the headers of both requests and see whether the IP changed in the middle of the session.
Two-minute diagnosis
First paste the line into the proxy checker. If the proxy works there, the cause is in your app or its settings. If not, test the line from a terminal:
curl -v -x "http://USERNAME:PASSWORD@gw.prokso.com:823" https://api.ipify.org
- A
< HTTP/1.1 407line right afterCONNECTmeans the proxy answered. The name after the code, for exampleNO_USER, points to the cause. - The proxy answered
CONNECTwith 200 and then another code arrived - the proxy works, and that answer came from the website. - No answer at all, only a timeout - the connection never reached the proxy: check the host, port and network.
FAQ
How is 401 different from 403?
401 means “you are not authenticated”: the site does not know who you are. 403 means “I know who you are, but access is forbidden”. About 403 through a proxy, see the <a href="/en/errors/403-forbidden">separate page</a>.
Can a proxy return 401?
A proxy answers sign-in errors with the 407 code. So a 401 through a proxy is almost always sent by the site itself or its API.
Why does the site ask me to sign in again after the IP changes?
Some sites treat an address change as a sign of a different device and reset the session. For such work, use a sticky IP and set a session duration long enough for your task.
Other proxy errors
Residential $1.59, mobile $2.50, datacenter $0.65 per GB
Sign up in a minute, get access right after payment.