406 Not Acceptable Error: What it Means & How to Fix
This error appears when the server returns data in unsupported format
406 Not acceptable error is an HTTP response status code, and it appears if the server can’t properly return the data. However, there are a few ways to fix this issue, if it happens in your code.
How do I fix HTTP error 406?
Table of contents
1. Adjust the accept parameter in your code
- Open your code.
- Locate the line that sends the request and change it like this:
profile = personality_insights.profile(profile_text, accept='application/json', content_type='text/plain').get_result()
- Save changes.
Note that the accept parameter can only use application/json or text/csv value.
2. Use JSON.stringify
- Open your code.
- Make sure you add a JSON.stringify function, like this:
$.ajax({ url: 'https://example.com:9200/incidents/incidents', type: 'POST', data: JSON.stringify(this.incident), dataType: 'json' })
- Lastly, save the changes.
Keep in mind that this solution only works if the object is not a properly serialized JSON string.
3. Make sure you specify the user-agent in the header
- Open your code editor.
- Next, add the request headers and include them like this:
page_url = 'https://examplepage.com' headers = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36', } rawpage = requests.get(page_url,headers=headers)
- After doing that, all you need to do is to save the changes.
What is the difference between HTTP 404 and 406?
The HTTP 406 client error response appears when the client sends a legitimate request, but the returned data isn’t in the accepted format.
On the other hand, HTTP error 404 response code is one of the most common client-side errors and probably the most known 4xx error. It appears when the request can’t be processed because the requested data wasn’t found.
406 Not acceptable errors can appear in Java, Angular, and any other language that supports HTTP requests. This issue usually affects developers and not the average Internet users.
To fix it, ensure your client is configured to accept the specific type of data from the server as a response. You can also change server configuration and adjust configuration files so that the server and client both use the supported format.
FAQs
HTTP error 406 means the server cannot return a response that matches the format the client asked for. The issue often comes from request headers like Accept or Accept-Language that do not match what the server can provide.
It occurs when the client requests a specific content type, such as JSON or XML, and the server cannot serve that format based on the headers sent.
No. It is a temporary mismatch between what the client requests and what the server can send. Correcting headers or server responses usually resolves it.
No. The site is reachable, but it cannot send a representation that matches the client’s requested format.
This is just one of many errors you can encounter, and in the past, we covered HTTP error 431 and HTTP error 413, so don’t miss them if you need more information.
If you are dealing with other server-side issues, you might also encounter the HTTP error 503 Service Unavailable, which indicates that the server is temporarily unable to handle the request.
What method did you use to fix the 406 Not acceptable error in Nginx? Share your findings with us in the comments section.
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
User forum
0 messages