Guides

5 min readUpdated

406 Not Acceptable: what it means and how to fix it

Quick answer

HTTP 406 Not Acceptable means the server has no version of the resource that matches what the request said it can accept, in headers such as Accept or Accept-Language, and will not send a default version instead. Genuine 406s mostly come from APIs with strict content negotiation, when a client asks for a format the endpoint does not produce. On websites, a 406 after submitting a form is more often a security filter, such as ModSecurity on shared hosting, using the code to block the request.

01What does 406 Not Acceptable mean?

RFC 9110 defines 406 as the answer when the resource "does not have a current representation that would be acceptable to the user agent" according to the proactive negotiation headers in the request, "and the server is unwilling to supply a default representation". Those headers are Accept (formats such as text/html or application/json), Accept-Language, Accept-Charset and Accept-Encoding.

The second half of the definition explains why browsers rarely see a real 406. A server is allowed to ignore the negotiation headers and send its default version anyway, and most do. Browsers also end their Accept header with */*, which accepts anything. A 406 therefore means a server chose to be strict, or something other than content negotiation used the code.

02Which 406 do you have?

The response body usually tells you which of the two causes you are dealing with.

Response body or contextGenerated byCause
{"detail": "Could not satisfy the request Accept header."}Django REST frameworkContent negotiation: no renderer matches Accept
{"status": 406, "error": "Not Acceptable", ...}Spring Boot's default error responseContent negotiation: the handler does not produce that type
406 for a request with an unsupported format, for example .xmlRuby on Rails (ActionController::UnknownFormat)Content negotiation in respond_to
An appropriate representation of the requested resource could not be found on this server.Apache httpd's built-in 406 pageContent negotiation (MultiViews or type maps), or a security rule configured to deny with 406
406 right after submitting a form or uploading content, on shared hostingA web application firewall such as ModSecuritySecurity filter: the content matched a rule

03Fixing a 406 from an API

Look at the Accept header your client really sends, not the one you think it sends. HTTP libraries, SDKs and API tools often set it for you, and a typo or a vendor-specific type the endpoint does not know is enough for a strict server to refuse. curl, Python requests and the browser fetch API send Accept: */* by default, so a request that works in curl but fails in your code usually differs in exactly this header.

Compare the two requests below. If the first works and the second returns 406, the endpoint does not produce the format you asked for: change the header to a type the API documents, or drop it.

  • Send a type the API documents, such as Accept: application/json, or a versioned vendor type if the API requires one
  • Check Accept-Language and Accept-Charset as well; a few servers negotiate on those too
  • Remove client defaults that add a narrow Accept header to every request
  • In API tools, check the generated headers tab rather than only the ones you typed
Compare the response with a generic and a specific Accept header
curl -si https://api.example.com/items -H 'Accept: */*' | head -n 5
curl -si https://api.example.com/items -H 'Accept: application/xml' | head -n 5

# show exactly what your client sends
curl -sv -o /dev/null https://api.example.com/items 2>&1 | grep '^> '

04If you run the API: when to send 406

The standard lets you choose between refusing and sending a default. For most APIs a default is kinder: answer with your standard format, usually JSON, and set Content-Type accordingly. Clients that genuinely cannot handle it will notice the type; clients with a sloppy Accept header keep working.

If you do refuse, say why. RFC 9110 asks the server to include a list of the representations it can provide, so the client can choose one. Log the rejected Accept values for a while: a spike after a release usually means a client library changed its defaults, not that users want a new format.

05When a 406 is really a security block

Security filters can deny a request with any status code their operator chooses, and some hosting providers configure ModSecurity to answer 406 instead of the more common 403. A 406 that appears only when a form contains certain text, such as code snippets, SQL-like words or long encoded strings, or only for some tools or user agents, is almost certainly such a rule and has nothing to do with content negotiation.

As the site owner, find the rule before changing anything. The web server's error log or the ModSecurity audit log records the denial with the rule's ID, in a line such as ModSecurity: Access denied with code 406, followed by the matched rule and its [id]. Narrow that one rule for the affected path or parameter, or ask your host to, rather than switching the filter off for the whole site; a WAF that is disabled after one false positive protects nothing. How 403 blocks from a WAF are traced works the same way, and virtual patching explains why those rules exist.

06What can visitors do about a 406?

If the error appears after you submit a form, the site's security filter probably objected to what you entered. Try again without unusual characters, pasted code or long links, and if that is not possible, send the site owner the time, the page and what you submitted. If every page returns 406, try another browser or a private window to rule out an extension that rewrites request headers, then report it: a site-wide 406 is a server configuration fault.

Questions

Frequently asked questions

01Is a 406 error a client or a server problem?
It is a 4xx code, so formally the request is the problem: it asked for a format the server will not provide. In practice the cause is often on the server, either a strict API that could send a default instead, or a security filter that uses 406 to block requests. The response body usually shows which.
02What is the difference between 406 and 415?
406 Not Acceptable concerns the response format: the server cannot produce what the Accept header asks for. 415 Unsupported Media Type concerns the request body: the server cannot process the format named in the request's Content-Type header. Fix the Accept header for a 406 and the Content-Type header for a 415.
03Why do I get a 406 when I submit a form?
Most likely a web application firewall on the site, such as ModSecurity on shared hosting, matched something in what you submitted and blocked it with status 406. Retry without unusual characters, code or long links, or contact the site owner, who can find the exact rule in the server logs and adjust it.
04How do I fix a 406 in curl or Postman?
Check the Accept header. Both tools send Accept: */* unless you change it, so a 406 usually means a custom header asks for a format the endpoint does not produce. Set it to a type the API documents, such as application/json, or remove it, and compare the responses.

Sources

Sources and verification

  1. 01RFC 9110: HTTP Semantics, section 15.5.7 (406 Not Acceptable) and section 12 (content negotiation) · RFC Editor
  2. 02406 Not Acceptable · MDN
  3. 03Content negotiation in Apache HTTP Server · Apache Software Foundation
  4. 04Content negotiation · Django REST framework
  5. 05Action Controller overview: respond_to and formats · Ruby on Rails Guides
  6. 06ModSecurity Reference Manual (v2.x): status and deny actions · OWASP ModSecurity
  7. 07OWASP CRS documentation · OWASP CRS

Last updated