4xx Client Errors

HTTP 406 Not Acceptable

The resource cannot generate content matching the Accept headers sent by the client.

When is 406 used?

  • Client only accepts XML but server returns JSON
  • Content negotiation failure

How to handle a 406 response

Inspect the request — URL, method, headers, credentials, and body. Retrying the same request unchanged will usually fail again; 429 is the exception, where you should wait for the Retry-After period.

Check the status code a URL returns from the command line:

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

How to return 406 from your server

Node.js (Express)

res.status(406).json({ message: 'Not Acceptable' });

Python (Flask)

return {"message": "Not Acceptable"}, 406

Go (net/http)

w.WriteHeader(406)

Frequently Asked Questions

What does HTTP 406 mean?

406 Not Acceptable: The resource cannot generate content matching the Accept headers sent by the client.

Is 406 an error?

Yes. 406 is in the 4xx Client Errors class. Client errors: the request is malformed, unauthorized, or targets something that does not exist.