rhsimplex / image-match

🎇 Quickly search over billions of images
2.94k stars 405 forks source link

POST /tester2/image?refresh=false [status:406 request:0.003s] elasticsearch.exceptions.TransportError: <exception str() failed> #88

Open DIT4FUN opened 6 years ago

DIT4FUN commented 6 years ago

I am using a VMware Centos7 system,and install all software follow the guide doc! and then i test the following code:

import elasticsearch
from image_match.elasticsearch_driver import SignatureES
es = elasticsearch.Elasticsearch()
es.indices.create('tester2')
ses = SignatureES(es, index='tester2')
ses.add_image('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg')
list = ses.search_image('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg')
print(list)

then i got this error!

POST /tester2/image?refresh=false [status:406 request:0.003s]
Traceback (most recent call last):
  File "/home/diters/PycharmProjects/imageMatch/imageMatchServer.py", line 6, in <module>
    ses.add_image('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg')
  File "/usr/local/python3/lib/python3.6/site-packages/image_match/signature_database_base.py", line 203, in add_image
    self.insert_single_record(rec, refresh_after=refresh_after)
  File "/usr/local/python3/lib/python3.6/site-packages/image_match/elasticsearch_driver.py", line 88, in insert_single_record
    self.es.index(index=self.index, doc_type=self.doc_type, body=rec, refresh=refresh_after)
  File "/usr/local/python3/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/python3/lib/python3.6/site-packages/elasticsearch/client/__init__.py", line 279, in index
    _make_path(index, doc_type, id), params=params, body=body)
  File "/usr/local/python3/lib/python3.6/site-packages/elasticsearch/transport.py", line 329, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/usr/local/python3/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 109, in perform_request
    self._raise_error(response.status, raw_data)
  File "/usr/local/python3/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 108, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.TransportError: <exception str() failed>
dsandor commented 6 years ago

Hi @DIT4FUN I came across this issue as well. The problem is resolved by requiring a newer version of the elasticsearch-py module. Do this by adding the following line in your requirements.txt file.

tldr; Elastic Search 6+ no longer assumes application/json so you have to upgrade the elasticsearch-py module you are using so it passes the correct headers to elastic search.

For reference: https://github.com/elastic/elasticsearch-py

requirements.txt

# Elasticsearch 6.x
elasticsearch>=6.0.0,<7.0.0

The discusstion of this can be found here: https://github.com/elastic/elasticsearch-py/issues/718

@rhsimplex, you can probably close this or tag it as a question for others to see.

peaboard commented 6 years ago

@dsandor thanks this works perfectly!

@DIT4FUN In addition, if you're not using a requirements.txt file, running pip with requirements like this also works.

pip install 'elasticsearch>=6.0.0,<7.0.0'