Skip to the content

401 Unauthorized

The request needs valid credentials and didn't have them: nobody is logged in, or the token is wrong or has expired.

Class
4xx Client error. The request is the problem: a wrong address, missing credentials, data the server can't accept.
Defined in
RFC 9110

What it looks like

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="api", error="invalid_token"

Share this tool:TwitterFacebookLinkedInWhatsAppEmail

What causes it

For a request to something protected, without credentials or with ones the server rejects. The response has to carry a WWW-Authenticate header that names the scheme to use, such as Basic or Bearer. With Basic, that header is what makes a browser show its login dialog.

What to do about it

Log in, or send the request again with valid credentials.

For an API: check that the Authorization header really is sent (a redirect to another host drops it), that the token has not expired, and that it belongs to this environment. A 401 that keeps coming back points at a wrong key or secret. Lacking the rights for something is a 403.

With OAuth an access token that has run out is the everyday cause. The remedy is to get a new one with the refresh token and to send the request again, which most client libraries can do by themselves.

Not to be confused with

403 ForbiddenThe server knows who you are, or doesn't care, and still refuses.
407 Proxy Authentication RequiredThe same demand, made by a proxy.

How Google treats it

Google treats a 401 like any other 4xx: the page is not indexed, and one that was indexed is dropped. Its documentation warns against using 401 or 403 to slow the crawler down.

All codes are on the list of HTTP status codes, which can be searched by number and by word.

See all 12