从我的电脑上搜索Heroku盆景

2024-09-27 22:33:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试ping我的Elasticsearch实例(通过Bonsai an 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()

我收到以下错误消息:

^{pr2}$

我相信这个错误是由于我没有https证书,所以我使用了HTTP,删除了URL和regex中的s,并将{}切换为False,但我得到了以下错误:

^{3}$

如何将计算机中的数据插入Heroku上的elasticsearch?在


Tags: fromhttpsimportauthhosturlherokues
2条回答

你可能在用Python3。 问题在于您的python版本和urlib的行为方式。在

快速解决办法可以是:

es_header = [{
'host': host,
'port': 443,
'use_ssl': True,
'http_auth': (auth[0],auth[1]),
'verify_certs': False
}]

但这条路不安全。一个更明确的解决办法是在要求.txt公司名称:

^{pr2}$

输入终端:

pip install -r requirements.txt

在实例化elasticsearch的文件中:

import certifi

然后启动与您之前启动的代码完全相同的代码,它应该可以工作并将是安全的。在

问题是客户端找不到根证书(这些证书位于运行代码的计算机上)。正如异常所提到的,您应该能够使用pip安装certifi,然后在脚本中只安装{},并且它应该在没有问题as described here的情况下运行。在

相关问题 更多 >

    热门问题