What Is a 406 Status Code?
The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request1, and the server is unwilling to supply a default representation.
The server SHOULD generate a payload containing a list of available representation characteristics and corresponding resource identifiers from which the user or user agent can choose the one most appropriate. A user agent MAY automatically select the most appropriate choice from that list. However, this specification does not define any standard for such automatic selection, as described in RFC7231 Section 6.4.1.
406 CODE REFERENCES
Rails HTTP Status Symbol
Go HTTP Status Constant
Symfony HTTP Status Constant
Python2 HTTP Status Constant
Python3+ HTTP Status Constant
Python3.5+ HTTP Status Constant
HttpComponents Core org.apache.hc.core5.http.HttpStatus.SC_NOT_ACCEPTABLE
406 status code example
Here is an example of a request and response that might result in a 406 Not Acceptable status code:
GET /products HTTP/1.1
In this example, the client is requesting the “products” resource from the server, and is specifying that it would like to receive the response in XML format.
HTTP/1.1 406 Not Acceptable
The server cannot produce a response matching the request.
In this example, the server is unable to fulfill the request as the client has specified an Accept header requesting a format that the server is unable to produce. The server responds with a 406 Not Acceptable status code, indicating to the client that the request could not be fulfilled in the specified format.
What causes a 406 status code?
A 406 Not Acceptable status code is typically caused by one of the following reasons:
- Requested resource not available in the requested format: The client may have requested a resource (such as a file or web page) in a format that is not available on the server.
- Unsupported Accept header: The client’s request may include an “Accept” header that specifies the desired response format. If the server cannot provide a response in that format, it will return a 406 status code.
- Unsupported character encoding: If the client request includes a “Content-Type” header that specifies a character encoding that is not supported by the server, it may return a 406 error.
- Mismatched request and response content types: The server may be unable to provide a response in the requested format due to a mismatch between the content types specified in the client’s request and the server’s response.
In general, a 406 error occurs when the server cannot fulfill the client’s request due to a problem with the requested resource, the request headers, or the server configuration.
How to fix a 406 status code
A 406 Not Acceptable status code means that the server is unable to provide a response that matches the client’s requested format, typically specified in the Accept header of the request. Here are a few ways to potentially resolve a 406 error:
- Update the Accept header: If the client specifies an Accept header in the request, it’s possible that the server doesn’t support the requested format. Try updating the Accept header to a different format or removing it altogether and see if that resolves the issue.
- Check the server configuration: The server may not have the necessary components or configuration to provide a response in the requested format. Check the server logs and configuration to ensure that it’s capable of producing the desired response.
- Provide additional parameters: Depending on the specific use case, it may be possible to modify the request to include additional parameters that allow the server to provide a response in the desired format. For example, some APIs allow clients to specify additional parameters in the request URL to specify the response format.
- Contact the server administrator: If you’ve tried the above steps and the error persists, it’s possible that the server administrator may need to make changes to the server configuration or update the API documentation to support the desired response format. Contact the administrator or the API provider for further assistance.
Does a 406 status code affect search engine optimization (SEO)?
If search engines are unable to access or index a resource due to a 406 error, it could negatively impact the visibility and ranking of the affected page or site in search engine results pages (SERPs). This can ultimately result in decreased traffic and visibility for the affected site.
Additionally, if users are encountering 406 errors when trying to access certain resources on a site, they may be less likely to continue using or recommending the site, which could have indirect effects on SEO as well.
- Learn about web development
- Learn about SEO
- Web development services from WebFX
- SEO services from WebFX
- MDN Web Docs