406 Not Acceptable
The server cannot produce a response in any format the client said it accepts in its Accept headers.
What 406 Not Acceptable means
Clients send Accept, Accept-Language or Accept-Encoding to say what they can handle. If nothing on the server matches, it can return 406, although many servers send a default format instead.
406 is about the format you want back. 415 is the opposite: the server cannot read the format you sent.
Common causes
- An Accept header that is too strict, such as Accept: application/xml for an API that only returns JSON.
- A server security filter (some ModSecurity setups, for example) configured to block requests with 406.
How to fix 406 Not Acceptable
- Loosen the Accept header, or send Accept: */*.
- Check which content types the API supports and ask for one of them.
- If you run the server, check security filter logs, and consider returning a default format instead.
Headers that go with it
AcceptAccept-LanguageAccept-Encoding
Example response
HTTP/1.1 406 Not Acceptable
Content-Type: text/plain; charset=utf-8
406 Not AcceptableHow to check for a 406 response
cURL
# Print only the status code
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/JavaScript (Node.js)
const res = await fetch("https://example.com/");
if (res.status === 406) {
console.log(res.status, res.statusText);
}Python
import requests
res = requests.get("https://example.com/")
if res.status_code == 406:
print(res.status_code, res.reason)Go
res, err := http.Get("https://example.com/")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 406 {
fmt.Println(res.Status)
}Specification
406 Not Acceptable is defined in RFC 9110, section 15.5.7.
Related status codes
- 415
The server refuses the request body because its format, given by Content-Type or Content-Encoding, is not supported.
- 300
The resource has more than one representation, such as different languages or formats, and the client needs to pick one.
- 400
The server could not understand the request because something in it is malformed, like broken JSON, bad syntax or invalid headers.