python3连接ES(elasticsearch)时https请求处理

python环境:python3.8.8
ES(elasticsearch)版本 7.1.1

1.进行https请求时,忽略ssl证书验证,将context赋值给ssl_context 即可

from elasticsearch import Elasticsearch
#查看证书位置
import ssl
##忽视证书
context = ssl._create_unverified_context()

ES =["127.0.0.1:9200"]
# 创建elasticsearch客户端
es = Elasticsearch(
    ES,
    http_auth=('username', 'passward'),##账号密码
    scheme="https",
    ssl_context=context,
)
index = "index"
print(es)
print(es.ping())
res = es.indices.exists(index = index)
print(res)

2.elasticsearch.exceptions.UnsupportedProductError: The client noticed that the server is not a supported distribution of Elasticsearch

这里的问题是python中的elasticsearch 包的版本和 ES服务端的版本不匹配

可以改变python 中elasticsearch的版本,与服务端ES版本保持一致

pip uninstall elasticsearch
pip install elasticsearch==7.1

3.ssl证书报警

/usr/anaconda/lib/python3.8/site-packages/urllib3/connectionpool.py:997: InsecureRequestWarning: Unverified HTTPS request is being made to host ‘172.16.0.73’. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

import requests

# 加上这行代码即可,关闭安全请求警告
requests.packages.urllib3.disable_warnings()
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值