python3连接ES(elasticsearch)时https请求处理
2021/8/25 11:36:01
本文主要是介绍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()
这篇关于python3连接ES(elasticsearch)时https请求处理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享