Hello guys, could you please help me how to set that library to use master version or Python ES module? Where can I modify that requirements.txt file?
(Im now trying to learn how to use ES with Python to create some visualisations in Kibana so Im trying to import some data from online StarWars API :) ) IM getting transport error 406.
I have found this solution but I don't know where that requiremets.txt file is located.
Thank you in advance
Why do you need a master version? The issue you are referring to has been released in 5.2.0 and all versions since then. You shouldn't have to need the master branch version.
Hi! Firstly thank you very much for your answer. I really appreciate your willingness to help and that you spent some time to help.
I have to say that I am just a beginner in Python same as in ES implementation so I’m now in my first steps in this programing.
I’m using Python 3.5.3 on Debian 9. I have installed ES version 6.1.2. I have installed also python ES module (via pip through command line – so I’m not sure about a version of this module). My goal is to get some data into ES to make some dummy dashboard in Kibana. I want to learn how to extend this further to finally harvest data from AI neuron net afterwards.
So far I’m just stucked to get some testing data to ES. If I ran a script I get TransportError(406, 'Content-Type header []... error. Data could look like follows (ID will be primary key, N_D is some process ID, etc.):
{"ID ": "1", "N_ID": "1011","A_ID": 10,"NOTE": "P","VALUE": 4}
{"ID ": "2", "N_ID": "1100","A_ID": 9,"NOTE": "P","VALUE": 2}
{"ID ": "2", "N_ID": "1101","A_ID": 8,"NOTE": "P","VALUE": 2}
{"ID ": "2", "N_ID": "1111","A_ID": 7,"NOTE": "P","VALUE": 1}
My Python script looks like this:
import requests
res = requests.get('http://localhost:9200')
from elasticsearch import Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
import json
import codecs
import random
reader = codecs.getreader('utf-8')
class MyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (bytes, bytearray)):
return obj.decode("ASCII") # <- or any other encoding of your choice
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
#test input of data into ES
i = 1
j = 10
while j > 1:
r={"ID": str(i), "N_ID": "1011","A_ID": str(j),"NOTE": "P","VALUE": str(random.sample(set([0, 1, 2, 3, 4]), 1))}
#print(r)
es.index(index='XML_test', doc_type='tag', id=str(i), body=json.dumps(r,cls=MyEncoder))
i = i+1
j = j-1
After I run it I get following error:
b'{\n "name" : "5SgBoB3",\n "cluster_name" : "elasticsearch",\n "cluster_uuid" : "ngDStT9GTmm8BKmPOOTz5w",\n "version" : {\n "nu
mber" : "6.1.2",\n "build_hash" : "5b1fea5",\n "build_date" : "2018-01-10T02:35:59.208Z",\n "build_snapshot" : false,\n "lu
cene_version" : "7.1.0",\n "minimum_wire_compatibility_version" : "5.6.0",\n "minimum_index_compatibility_version" : "5.0.0"\n }
,\n "tagline" : "You Know, for Search"\n}\n'
PUT /XML_test/tag/1 [status:406 request:0.007s]
Traceback (most recent call last):
File "insert.py", line 24, in <module>
es.index(index='XML_test', doc_type='tag', id=str(i), body=json.dumps(r,cls=MyEncoder))
File "/usr/lib/python3/dist-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/elasticsearch/client/__init__.py", line 254, in index
_make_path(index, doc_type, id), params=params, body=body)
File "/usr/lib/python3/dist-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/usr/lib/python3/dist-packages/elasticsearch/connection/http_urllib3.py", line 89, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/lib/python3/dist-packages/elasticsearch/connection/base.py", line 105, 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')
What I'm doing wrong?
Thank you!
I am sorry, but I cannot replicate this locally, there is something in your environment that makes this not work properly. You do have the correct elasticsearch-py version and the header should be set. You shouldn't have to define your own serializer as the default should work just fine, you can just pass in python dictionaries to the API, no need to serialize things manually into json.
I keep getting this error: pyelasticsearch.exceptions.ElasticHttpError: (406, 'Content-Type header [] is not supported')
My code is here: https://github.com/rjurney/Agile_Data_Code_2/blob/master/ch04/web/on_time_flask_template.py#L117-L152
What should I do? If you run the script ec2.sh in that project, and then follow the setup instructions and run conert_data.py and pyspark_to_elasticsearch.py in ch04/ you can reproduce this issue. A ot of work, I know :)
Which elasticsearch version are you using?
Elasticsearch 6.x.x makes you specify the header Content-Type when making a request like this:
curl -H "Content-Type: application/json;charset=UTF-8" -XGET 'http://127.0.0.1:9200/_count?pretty' -d '{"query":{"match_all":{}}}'
Looks like the pyelasticsearch module doesn't do this by default.
Using elasticsearch Official client instead of pyelasticsearch should fix this.
@rjurney pyelasticsearch is a completely different (and deprecated) package - https://github.com/pyelasticsearch/pyelasticsearch
Hello, I also encountered TransportError: TransportError (406, u'Content-Type header [] is not supported '), using python elasticsearch, how to solve it
@jjsmd123456 what is your version of elasticsearch-py that you are using? most likely you just need to update it.
Hi, I am also just started readying elasticsearch and I am not a Python developer.
I am trying to upload a json to my standalone elasticsearch through Rest service.
I tried uploading json with content-type = application/x-ndjson and it is able to load it.
Not sure whether it helps.
So what I was finding was the version of pyelasticsearch was too old for my version of elasticsearch, so I upgraded that, only to fail on django-haystack version being too old, upgrading haystack upgraded Django and now I have just python issues to resolve.
@mark0978 pyelasticsearch is a different repository than this.
If you want to use this library you should install pip install elasticsearch.
Also, I'm not trying to bash haystack it's a very robust and popular library. BUT I'd recommend checking out elasticsearch-dsl-py for more advanced features and better integration with elasticsearch.
Unfortunatly haystack has to keep mimimum functionality between multiple search engines, where dsl-py only works with elasticsearch and can expose a lot more powerful functionality.
I'll take a look, this is just to support an existing platform that is sorely out of date, I'll see what would be needed to go more directly to elasticsearch
Sorry to repeat the issue, but it seems not to have been solved. I am very new to python and Elastic Search. Just today I installed es by
sudo pip install elasticsearch
Amd my browser shows the following, when I call http://localhost:9200/
{
"name" : "twwqM5V",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "t2EOo0GbRvWmx5ZnNqGp_Q",
"version" : {
"number" : "6.2.3",
"build_hash" : "c59ff00",
"build_date" : "2018-03-13T10:06:29.741383Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
So, everything seems insane.
But folowing minimal example does not work
from elasticsearch import Elasticsearch
from elasticsearch import TransportError
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
doc = {
'author': 'me',
'text': 'go,
}
try:
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['created'])
except TransportError as e:
print(e.info)
The execution dies with:
{u'status': 406, u'error': u'Content-Type header [] is not supported'}
So, what is wrong?
Thank you very much!
You have a version mismatch between your python code and your elasticsearch
system. Make sure the versions match. Also I think you want
elasticsearch-py instead of just elasticsearch.
On Sat, Apr 7, 2018 at 4:52 PM, Сергей notifications@github.com wrote:
Sorry to repeat the issue, but it seems not to have been solved. I am very
new to python and Elastic Search. Just today I installed es bysudo pip install elasticsearch
Amd my browser shows the following, when I call http://localhost:9200/
{
"name" : "twwqM5V",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "t2EOo0GbRvWmx5ZnNqGp_Q",
"version" : {
"number" : "6.2.3",
"build_hash" : "c59ff00",
"build_date" : "2018-03-13T10:06:29.741383Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}So, everything seems insane.
But folowing minimal example does not workfrom elasticsearch import Elasticsearch
from elasticsearch import TransportError
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
doc = {
'author': 'me',
'text': 'go,
}
try:
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['created'])
except TransportError as e:
print(e.info)The execution dies with:
{u'status': 406, u'error': u'Content-Type header [] is not supported'}So, what is wrong?
Thank you very much!—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/elastic/elasticsearch-py/issues/718#issuecomment-379501822,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGeplklqGyfbPtBr6IxoU7pJdZcmFKHks5tmTUVgaJpZM4RyBYF
.
1.pip install elasticsearch==5.2.0
2.in lib/python2.7/site-packages/pyelasticsearch/client.py line:271
change _,prepped_response = ...
to prepped_response = ...
solve the problem
I am getting an error "TransportError(406, u'Content-Type header [] is not supported', {u'status': 406, u'error': u'Content-Type header [] is not supported'}))" .
My Django version is 1.9.13, python version is 2.7.15, elasticsearch version is 2.2.0. @HonzaKral .
In my local system, I am running the elasticsearch version 6.4.1, using the command "elasticsearch".When I hit the url(http://localhost:9200/) it returns me a message .
@chandankiwitech elasticsearch-py version 2.2.0 does not support elasticsearch 6.4, you need to upgrade the python library to 6.x as well
Thanks, @HonzaKral
I degrade the elasticsearch 2.2.0 but still, I am getting the same issue.
"TransportError(406, u'Content-Type header [] is not supported', {u'status': 406, u'error': u'Content-Type header [] is not supported'}))".
You need to upgrate - pip install -U elasticsearch
me too
File "/usr/local/lib/python3.7/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 "/usr/local/lib/python3.7/site-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python3.7/site-packages/elasticsearch/connection/base.py", line 105, 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')
Me too
elasticsearch.exceptions.TransportError: TransportError(406, u'Content-Type header [] is not supported')`
Thanks for the help!! ...
pip install -U elasticsearch
Did the magic.
Most helpful comment
You have a version mismatch between your python code and your elasticsearch
system. Make sure the versions match. Also I think you want
elasticsearch-py instead of just elasticsearch.
On Sat, Apr 7, 2018 at 4:52 PM, Сергей notifications@github.com wrote: