Skip to content

401 Unauthorized explained, and how it differs from 403

By the ProxyOnly team · 16 Nov 2026 · 5 min read

A 401 asks you to authenticate. A 403 refuses you even if you did. How the two differ, how to fix each, and a demo with real curl output.

A 401 Unauthorized means the request lacks valid credentials for the thing you asked for. A 403 Forbidden means the server understood the request and refuses to carry it out, whoever you are. The difference is the question each one answers. A 401 says "who are you?" A 403 says "I have heard you, and the answer is no."

The standard, RFC 9110, puts it in nearly those terms. One thing makes the 401 confusing: its name. "Unauthorized" suggests a permissions problem, but the code is about authentication, proving your identity. Permissions are what the 403 is for.

The rule in four lines

  • No credentials, or credentials that are wrong or expired: 401. The server must also send a WWW-Authenticate header that says how to authenticate.
  • Valid credentials, but your account may not do this: 403.
  • Not allowed whoever you are, because of an IP rule, a country rule, a bot rule or a file permission: 403.
  • The server does not want to admit that the page exists: it may answer 404 instead. RFC 9110 allows a server to do this for a forbidden resource.

See it happen

We wrote a small server with two users. Alice can read /private. Only Bob can open /admin. It uses HTTP Basic authentication, which sends user:password in an Authorization header.

import base64, http.server
USERS = {"alice": "pw-alice", "bob": "pw-bob"}
ADMINS = {"bob"}
class Handler(http.server.BaseHTTPRequestHandler):
    def reply(self, code, body, headers=()):
        self.send_response(code)
        for name, value in headers:
            self.send_header(name, value)
        self.end_headers()
        self.wfile.write(body)
    def do_GET(self):
        user = None
        header = self.headers.get("Authorization", "")
        if header.startswith("Basic "):
            name, _, password = base64.b64decode(header[6:]).decode().partition(":")
            if USERS.get(name) == password:
                user = name
        if user is None:
            return self.reply(401, b"log in first\n", [("WWW-Authenticate", 'Basic realm="demo"')])
        if self.path == "/admin" and user not in ADMINS:
            return self.reply(403, b"you are %s, and admins only\n" % user.encode())
        self.reply(200, b"hello %s\n" % user.encode())
http.server.HTTPServer(("127.0.0.1", 9100), Handler).serve_forever()

Then we requested pages with curl. The output below is trimmed to the status line and the header that matters:

$ curl -si http://127.0.0.1:9100/private
HTTP/1.0 401 Unauthorized
WWW-Authenticate: Basic realm="demo"
$ curl -si -u alice:wrong http://127.0.0.1:9100/private
HTTP/1.0 401 Unauthorized
WWW-Authenticate: Basic realm="demo"
$ curl -si -u alice:pw-alice http://127.0.0.1:9100/private
HTTP/1.0 200 OK
$ curl -si -u alice:pw-alice http://127.0.0.1:9100/admin
HTTP/1.0 403 Forbidden
$ curl -si -u bob:pw-bob http://127.0.0.1:9100/admin
HTTP/1.0 200 OK

The first two requests got a 401 with the same challenge. The server did not know who was asking, or did not believe it. Alice's correct password got her into /private. On /admin the server knew exactly who she was and still refused, so the status changed to 403 and the WWW-Authenticate header disappeared. Logging in again as Alice cannot help, because the credentials were never the problem. The standard says a client should not automatically repeat a 403 request with the same credentials.

The Authorization header in Basic authentication is only encoded. printf 'alice:pw-alice' | base64 prints YWxpY2U6cHctYWxpY2U=, and anyone who sees that header can decode it. Use Basic authentication over HTTPS only.

How to fix a 401

  1. Check the credentials: user name, password, API key or token, with no stray spaces or line breaks.
  2. Check that the token has not expired. Tokens such as JWTs carry an expiry time, and a clock that is wrong by a few minutes can make a fresh token look invalid.
  3. Check the scheme. Authorization: Bearer TOKEN and Authorization: Basic ... are different, and some APIs expect a key in a custom header or a query parameter instead.
  4. Check that you are talking to the right environment. A staging key sent to the production API gets a 401.
  5. Look for redirects. HTTP clients usually drop the credentials when a redirect leaves the original host, so the second request arrives without them. We tested this: curl and Python's requests both authenticated to the first server, followed a redirect to another host and port, and got a 401 from the second. Adding curl's --location-trusted made the request succeed, and you should use that only when you trust the redirect target.
  6. In a browser, try a private window to rule out saved credentials that are out of date.

If the request goes through a proxy, a 401 is the website talking and a 407 is the proxy asking for credentials. See 407 Proxy Authentication Required, and the guide to finding your proxy credentials.

How to fix a 403

The credentials are accepted, or they are not the issue, so the fix is on the permission side:

  • Ask the owner of the resource to grant your account the right role.
  • Check whether the URL is the one you meant. A folder without an index page often gives a 403, not a 404.
  • Check for a firewall, IP allow list or country rule. The what is my IP tool shows the address a site sees, which you can send to the owner.
  • Read the response body. A server that wants to explain a 403 is allowed to.

The article on 403 Forbidden goes through the causes in detail, including the ones that come from firewalls and bot rules.

Real services are less tidy

Not every service follows the standard. You will meet APIs that return a 403 for a key that does not exist, and sites that answer a request without a session with a 200 and a login form. Treat the status code as a hint and read the body and the documentation. The pattern that holds is the one in the demo: a 401 is fixed by presenting better credentials, and a 403 is fixed by changing what the account is allowed to do, or by asking whoever set the rule.

What scripts should do

  • After a 401, refresh the credentials once, for example by requesting a new token, and try again. If it still fails, stop.
  • After a 403, stop and find out why. Retrying the same request with the same credentials will not change the answer.
  • Do not loop on failed logins. Some sites lock an account after several wrong passwords, and a tight loop can also be taken as an attack.
  • If a 403 appears while you are scraping, it is often a block, not a permissions problem. 403 and 429 errors when scraping and why websites block IPs and proxies explain how to tell.

Try it yourself

Create an account, add funds from US$1 and order a proxy in the country you need.

Keep reading