3

ローカルホストからPythonを使用してElasticSearch AWSにアクセスしようとしています(ブラウザからアクセスできます)。Pythonを使用してElasticSearch AWSにアクセスできません

from elasticsearch import Elasticsearch 
ELASTIC_SEARCH_ENDPOINT = 'https://xxx' 
es = Elasticsearch([ELASTIC_SEARCH_ENDPOINT]) 

私はこのエラーを受けています:

ImproperlyConfigured('Root certificates are missing for certificate validation. Either pass them in using the ca_certs parameter or install certifi to use it automatically.',) 

私はそれにアクセスするにはどうすればよいですか?私は証明書を設定していない、私はElasticSearchサービスにアクセスできるIPだけを解放した。

答えて

4

elasticsearch-py doesn’t ship with default set of root certificates. To have working SSL certificate validation you need to either specify your own as ca_certs or install certifi which will be picked up automatically.

from elasticsearch import Elasticsearch 

# you can use RFC-1738 to specify the url 
es = Elasticsearch(['https://user:[email protected]:443']) 

# ... or specify common parameters as kwargs 

# use certifi for CA certificates 
import certifi 

es = Elasticsearch(
    ['localhost', 'otherhost'], 
    http_auth=('user', 'secret'), 
    port=443, 
    use_ssl=True 
) 

# SSL client authentication using client_cert and client_key 

es = Elasticsearch(
    ['localhost', 'otherhost'], 
    http_auth=('user', 'secret'), 
    port=443, 
    use_ssl=True, 
    ca_certs='/path/to/cacert.pem', 
    client_cert='/path/to/client_cert.pem', 
    client_key='/path/to/client_key.pem', 
) 

https://elasticsearch-py.readthedocs.io/en/master/

2

私はそれをこのように行なったし、それが働いた:

from elasticsearch import Elasticsearch, RequestsHttpConnection 
from requests_aws4auth import AWS4Auth 

host = 'YOURHOST.us-east-1.es.amazonaws.com' 
awsauth = AWS4Auth(YOUR_ACCESS_KEY, YOUR_SECRET_KEY, REGION, 'es') 

es = Elasticsearch(
    hosts=[{'host': host, 'port': 443}], 
    http_auth=awsauth, 
    use_ssl=True, 
    verify_certs=True, 
    connection_class=RequestsHttpConnection 
) 
print(es.info()) 
3

for python 3.5 install certifi and use ca_certs=certifi.where() this will pass the certificates

import certifi 
from elasticsearch import Elasticsearch 

host = 'https://###########.ap-south-1.es.amazonaws.com' 

es = Elasticsearch([host], use_ssl=True, ca_certs=certifi.where()) 
関連する問題