What does a 406 Error code mean?

406 error

How to Fix a 406 Error

Sometimes mistakes happen on both the server and the client. These are called HTTP responses or status codes. One of these is the “406 error” or “406 Not Acceptable” message.

The 406 problem might show up when you visit a site. Or even worse, on your blog. The normal internet user might find it annoying, but for the owner of a website or app, it can be downright scary. Not only does any HTTP answer code, even the 406 error, look unprofessional and be hard to understand, it can also cost you sales and users.

It will talk about what the “406 Not Acceptable” error means, why it happens, how to fix it, and how to keep it from happening again.

The server SHOULD send a payload that has a list of all the possible representation traits and the resource names that go with them. The user or user agent can then pick the best one. It is possible for a user agent to pick the best option from that list on its own. However, this specification doesn’t set any rules for this kind of automatic decision.

406 LINKS TO CODE

Rails HTTP Status Sign: not_acceptable

Apache: HttpComponents Core org.apache.hc.core5.http.HttpStatus.SC_NOT_ACCEPTABLE

Keep the HTTP status the same: http.StatusNotAcceptable

Java: java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE

Symfony HTTP Status Response Always: HTTP_NOT_ACCEPTABLE

Python2 HTTP Status Value: httplib.NOT_ACCEPTABLE

Python 3 and up HTTP Status Constant: http.client.NOT_ACCEPTABLE

Python 3.5 and up HTTP Status Constant: http.HTTPStatus.NOT_ACCEPTABLE

.NET: HttpStatusCode.NotAcceptable

Angular 7: @angular/common/http/HttpStatusCode.NotAcceptable

http://rust: StatusCode::NOT_ACCEPTABLE

406 Example of a Status Code

A request and answer that might lead to a 406 Not Acceptable status code look like this:

Ask for

Go to /products in HTTP/1.1

Site host: example.com

Accept: XML or application

These lines show that the client is asking the server for the “products” resource and telling it that it wants the answer in XML format.

Ask for

It says HTTP/1.1 406 Not Acceptable.

Type of content: text/plain

Length of Content: 56

The server can’t respond to the request with an answer that fits it.

The server can’t meet the request in this case because the client included an Accept header that asks for a format that the server can’t provide. The server tells the client that the request could not be fulfilled in the manner that was given with a status code of 406 Not Acceptable.

What Is 406 Error?

The good news is that the “406 Not Acceptable” HTTP error message doesn’t happen nearly as often as the “404” server error (which usually means the page doesn’t exist) or even the “301” or “500” errors. Because of this, you should not see this one as often.

There is a small but possible chance that the 406 mistakes will cause problems for your website. It looks like this most of the time:

Most of the time, the message says:

Not Acceptable

An appropriate representation of the requested resource could not be found on this server. 

Then, it sometimes tells you which “requested resource” is the problem. At the end, it gives you other messages or server information:

The 406 error message looks and says different things based on the website, host, and browser used to access the website. The 406 error might show where the mistakes are coming from. Sometimes it’s just a “406 Not Acceptable” message that doesn’t tell you anything that can help you fix the issue.

Let’s say that browsers didn’t send these secret messages and instead spoke plain English. That is why the computer would say something like this:

Hey there I look things up. When I tried to show this page, one of two things went wrong:

  1. The server for the website sent me the wrong type of file, so I can’t take it.
  2. The website’s server doesn’t follow some security rules or settings.

So, please fix the problem or tell the computer to use one of the file types I accept. Here are the types of files I can read, just in case you were asking.

Browsers should be more like that!

There’s a problem with how the server and the browser or machine that is showing the web application talk to each other. The browser either can’t read what’s going on or can’t check the data because it doesn’t meet certain standards.

Now we have to answer some questions to find out why we didn’t understand each other.

On the server or the client?

The HTTP response status codes in the 4xx range are all client error replies. This group is different from 5xx classification errors, which are server error replies and include the 504 Gateway Timeout Error.

Still, seeing a 4xx error doesn’t always mean the problem is on the client side. The “client” is the web browser or device that is used to view an app.

The server might be to blame for the 406 Error sometimes, since the error is caused by a network object. It’s possible that the server isn’t set up right and can’t handle the request properly. It could be a problem with how the data is being sent.

This post will talk about problems on both the client side and the server side. But first, let’s make sure you have everything you need to test and diagnose your app.

Start by making a full copy of the application.

You should make a full backup of your application, database, and any other parts of your website or application before you try to fix any problems.

To make things even safer, make a full copy of the app and put it on a separate staging server that only you can view. This is because a staging server is a safe place to test all possible fixes for the problem without putting your live service at risk.

Getting a 406 Not Acceptable error

As we talked about at the beginning, a 406 Not Acceptable Error means that the user agent (usually a web browser) asked for an acceptable resource but included a special Accept- header in the request. The Accept- header tells the server that only certain types of data can be in a valid answer.

Here are a few examples of how this could happen:

  • The user agent may be set to a language or region that the server does not support. A user agent might use the Accept-Language request header to say that French is an acceptable language (Accept-Language: fr). Still, a 406 code might be the only right answer if the server can’t serve a response in French.
  • The client software (user agent) can ask the server to send a certain kind of information. These types of material, which are also called MIME types, describe things like plain text (text/plain), PNG images (image/png), mp4 videos (video/mp4), and more. So, the client can add the Accept message to the request and tell the server exactly what MIME type to send (for example, Accept: application/XML). It’s possible that a 406 Not Acceptable response is needed if the server can’t give the desired content type.

There are a few more Accept-headers that can be sent with HTTP requests. Still, the vast majority of situations are like the ones above: The user agent asks for a specific type of answer, and the server either gives it or sends back a 406 code, which means it can’t handle the request.

Troubleshooting the client side to work again

Since 406 Not Acceptable is a client error answer code, you should first check for any problems on the client side. Try these things on the browser or gadget that is giving you trouble.

See the URL that was asked for.

Since 406 Not Acceptable is a client error answer code, you should first check for any problems on the client side. Try these things on the browser or gadget that is giving you trouble.

For instance, a call to the URI https://airbrake.io?json might tell the server that it needs a JSON response. Since 406 codes don’t show up as often as 404 codes, a 406 could mean that the requested URL is legal, but the browser might not understand the correct request type. In either case, you should check the URL that is giving you the 406 Not Acceptable error again to make sure it is the right one.

Fixing Bugs in Common Platforms

Let’s say that the server that is giving you the 406 Not Acceptable error is running standard software packages. In that case, you might want to start by checking out how stable and useful those sites are.

Most content management systems (CMS), like WordPress, Joomla!, and Drupal, are well-tested before they are used for the first time. Since you’re changing the plugins or PHP code underneath, it’s too easy to make a mistake that leads to a 406 Not Acceptable.

Here are some tips to help you fix issues with some of these well-known software programs.

Revert the most recent upgrades

If you just changed the content management system and then saw the 406 Not Acceptable error, you might want to go back to the version you had installed before.

Also, any add-ons or modules that you just updated can cause problems on the server, so going back to older versions of those may also help.

But there are times when some CMSs don’t let you change versions. This is probably because they think the base app and every new version that comes out are very stable and bug-free.

Uninstall new plugins, modules, or extensions

The exact names of these parts will change depending on the content management system you use. In the end, though, they all do the same thing for every system: they make the platform better than it is by adding extra features and powers.

Be careful, because these add-ons can pretty much take over the whole system and change the CMS’s code in any way they want. Because of this, you might want to get rid of any new apps you just added.

Check the database for changes you didn’t expect.

You can’t be sure that changes made by an extension will fully go back even if you remove it through the CMS dashboard.

This is especially true for a lot of WordPress add-ons. WordPress add-ons are free to do whatever they want inside the app, including accessing the database. So, they can change database records that don’t “belong” to the extension but were made and are handled by other extensions or even the base CMS.

Unfortunately, the app might not know how to undo changes made to database records, so it won’t take notice of those things when it’s being removed.

It can be hard to figure out what the problem is, but I’ve seen it happen more than once. If you’re pretty sure that an extension is what caused the 406 Not Acceptable Error, the best thing to do is to open the database and look through tables and records that were probably changed by the extension by hand.

Fixed problems on the server side

Here are some more server-side troubleshooting tips to help you figure out what might be wrong if you’re not using a CMS application or are sure the 406 Not Acceptable Error has nothing to do with that.

Check how your server is set up.

Most likely, your app is running on a server that uses either Apache or Nginx, which are the two most popular web server programs. One of the first things you can do to figure out what is causing these 406 Not Acceptable response codes is to look through the setup files for your web server software for any redirect or request handling instructions that were added by accident.

You will need to find a key file to find out which web server your app is using.

Apache Server

For Apache web servers, look for an.htaccess file in the top directory of your website’s file system.

If, say, your app is on a shared host, you’ll probably have a username that goes with the server account. Many times, you can find the program root directory at the following path:

[User Name]/home/public_html/That is where the.htaccess file would be.

.htaccess file at /home//public_html.

Once you’ve found the.htaccess file, open it in a text editor and look for lines that use RewriteXXX instructions. These are part of Apache’s mod_rewrite module. This piece doesn’t go into detail about how these rules work, but the main idea is that a RewriteCond directive sets up a text-based pattern that will be matched against URLs that are entered.

Let’s say a guest asks for a site URL that matches. When this happens, the request is sent to the right URL by the RewriteRule directive that comes after one or more RewriteCond directives.

One example of a RewriteRule is a rule that fits all requests that come in and don’t have an Accept: application/JSON request header.

A reroute and the error code 406 Not Acceptable are the results:

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/users/json/?.*$

RewriteCond %{HTTP_ACCEPT} !application/json

RewriteRule ^(.*)$ https://airbrake.io/users/json$1 [R=406,L]

Keep an eye on the R=406 flag at the end of the RewriteRule. It makes it clear that the answer code should be 406. This lets the user agents know that the resource is there, but the clear Accept- headers could not be met.

You can briefly remove any RewriteCondor RewriteRule directives that don’t seem to belong in the.htaccess file by prefixing them with the # character. Then, restart your web server to see if that fixes the problem.

Nginx

On the other hand, you’ll need to find a different setup file if your server is running Nginx. The name of this file is nginx.conf by default, and it can be found in /etc/nginx, /usr/local/nginx/conf, or /usr/local/etc/nginx.

Open nginx.conf in a text editor once you’ve found it and look for instructions that use the 406 response code flag.

Here’s an example of a block directive, which is a named set of directives that sets up a virtual server for airbrake.io and makes sure that, like above, a request to

A call to https://airbrake.io/users/json that doesn’t have an Accept: application/JSON request header will fail and get a 406 response code.

server {

    listen 80;

    listen 443 ssl;

    server_name airbrake.io;

    location /users/json {

        if ($http_accept != application/json) {

            return 406 https://airbrake.io/users/json$request_uri;

        }

    }

}

Check your nginx.conf file for any strange commands or lines that have the 406 flags in them. Any strange things should be commented out before the server is restarted to see if the problem is fixed.

While the configuration options for each type of web server can be very different, here are a few popular ones that you can look through, based on the type of server your app is running on:

Read the logs.

Logs will be kept on the server side by almost all web apps. Application logs usually keep track of what pages were requested, which servers were linked, what database results were found, and so on.

Server logs are about the hardware that is running the application. They usually show information about the health and state of all services that are connected to the server or the server itself.

To learn more about how to find the logs you need, type “logs [PLATFORM_NAME]” into Google if you’re using a CMS and “logs [PROGRAMMING_LANGUAGE]” and “logs [OPERATING_SYSTEM]” if you’re running a custom app.

Fix bugs in your scripts or application code

If nothing else works, there could be a problem with some special code in your app. Manually fixing your app and reading through application and server logs can help you figure out where the problem might be coming from.

Make a copy of the whole application on a local development machine and debug it step by step. This will let you repeat the exact situation where the 406 Not Acceptable happened and see the code that is being used when something goes wrong.

By using an error monitoring service, you can stop users from being affected by an unexpected 406 Not Acceptable Error in the future. Error Monitoring will help you find mistakes automatically and let you know as soon as they happen.

Does a result code of 406 have any effect on search engine optimization (SEO)?

If a 406 Not Acceptable status code stops search engines from accessing or properly indexing a site, it could have an effect on SEO.

Since a 406 error means that search engines can’t reach or index a resource, it could hurt the page or site’s visibility and ranking in search engine results pages (SERPs). This could lead to less traffic and exposure for the site in the long run.

Also, users may be less likely to keep using or suggest a site if they keep getting 406 errors when they try to access certain resources on it, which could have indirect effects on SEO as well.