Raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.TransportError: TransportError(406, 'Content-Type header [] is not supported')

GET /newsout/_search?size=10000 [status:406 request:0.004s]

Traceback (most recent call last):
File "run.py", line 2, in
from webapp import app
File "/home/default/idr/portal/webapp/init.py", line 5, in
import webapp.views
File "/home/default/idr/portal/webapp/views.py", line 11, in
recommender = recommend_articles.recommender_system()
File "/home/default/idr/portal/webapp/recommend_articles.py", line 101, in init
self.create_corpus()
File "/home/default/idr/portal/webapp/recommend_articles.py", line 110, in create_corpus
news = es.search(index='newsout', body={'query': {'match_all': {}}}, size=10000)['hits']['hits']
File "/home/default/idr/venv/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped
return func(*args, params=params, **kwargs)
File "/home/default/idr/venv/lib/python3.6/site-packages/elasticsearch/client/init.py", line 497, in search
params=params, body=body)
File "/home/default/idr/venv/lib/python3.6/site-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/home/default/idr/venv/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 86, in perform_request
self._raise_error(response.status, raw_data)
File "/home/default/idr/venv/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 102, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.TransportError: TransportError(406, 'Content-Type header is not supported')

i don't know where is the problem

The problem is here:

406, 'Content-Type header  is not supported'

You need to provide the application/json content type.
See https://www.elastic.co/fr/blog/strict-content-type-checking-for-elasticsearch-rest-requests

as just you said ,my mapping contains application/json content type.But,it doesn't work.

curl -X PUT "localhost:9200/newsout/_mapping/test-type" -H '
Content-Type: application/json' -d' {

"properties": {
    "author": { "type": "keyword"  },
    "date": {
        "type": "date",
        "format": "yyyy-MM-dd"
    },
    "description": {
        "type": "text",
        "analyzer": "french"
    },
    "topics": { "type": "keyword"  },
    "link": { "type": "text", "index": "true"  },
    "locations": { "type": "keyword"  },
    "organizations": { "type": "keyword"  },
    "persons": { "type": "keyword"  },
    "text": {
        "type": "text",
        "analyzer": "french"
    },
    "title": {
        "type": "text",
        "analyzer": "french"
    }
}

}'

the output is

{"acknowledged":true}

it seems that is the same error

iraise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.TransportError: TransportError(406, 'Content-Type header [] is not supported')

i m confused i don't understand this problem !!!!

The problem is most likely in the Python code I guess. You wrote this code right?

yes i wrote a part of this code , but ,i think maybe there is a problem with request or http_urllib3

What does your code look like? Not sure I can help though as I'm not a Python dev but I'm sure others could help.

thank you ,it s okay i fixed the problem

Would be great to share your solution for the next readers.

i ve just removed the wrong version for ulrlib3 and requests library python .

I retry to download them and it works.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.