![](/img/trans.png)
[英]Flask app hosted on Heroku shows Bokeh plot on my computer but not on any other computer
[英]Accesing elasticsearch on Heroku Bonsai from my computer
我正在嘗試ping我的Elasticsearch實例(通過Bonsai和Heroku插件部署)。 我已遵循他們的指南,並嘗試在計算機上執行以下代碼:
from elasticsearch import Elasticsearch
from settings import BONSAI_URL
import re, logging
# Log transport details (optional):
logging.basicConfig(level=logging.INFO)
# Parse the auth and host from env:
bonsai = BONSAI_URL
print(bonsai)
auth = re.search('https\:\/\/(.*)\@', bonsai).group(1).split(':')
host = bonsai.replace('https://%s:%s@' % (auth[0], auth[1]), '')
# Connect to cluster over SSL using auth for best security:
es_header = [{
'host': host,
'port': 443,
'use_ssl': True,
'http_auth': (auth[0],auth[1])
}]
# Instantiate the new Elasticsearch connection:
es = Elasticsearch(es_header)
# Verify that Python can talk to Bonsai (optional):
es.ping()
我收到以下錯誤消息:
elasticsearch.exceptions.ImproperlyConfigured: Root certificates are missing for certificate validation. Either pass them in using the ca_certs parameter or install certifi to use it automatically.
我認為此錯誤是由於我沒有https證書,所以我使用HTTP,方法是刪除URL和正則表達式中的s
,然后將use_ssl
切換為False,但出現以下錯誤:
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
如何將計算機中的數據插入Heroku上的elasticsearch中?
問題是客戶端找不到根證書(這些根證書位於運行代碼的計算機上)。 如例外所述,您應該能夠使用pip
安裝certifi
,然后只需在腳本中import certifi
,它就可以正常運行, 如此處所述 。
您可能正在使用Python3。 問題與您的python版本和urlib的行為有關。
快速修復方法可能是:
es_header = [{
'host': host,
'port': 443,
'use_ssl': True,
'http_auth': (auth[0],auth[1]),
'verify_certs': False
}]
但是這種方式並不安全。 更加確定的解決方法是在您的requirements.txt中寫下:
certifi
輸入您的終端:
pip install -r requirements.txt
在您要啟動elasticsearch的文件中:
import certifi
然后啟動與您之前啟動的完全相同的代碼,它應該可以正常運行並且很安全。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.