首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TypeError:__init__()缺少一个必需的位置参数:弹性搜索中的“方案”

TypeError:__init__()缺少一个必需的位置参数:弹性搜索中的“方案”
EN

Stack Overflow用户
提问于 2022-03-25 20:40:13
回答 3查看 4.7K关注 0票数 3

下面是我的密码-

Elasticsearch不是使用https协议,而是使用http协议。

代码语言:javascript
运行
复制
pip uninstall elasticsearch
pip install elasticsearch==7.13.4
import elasticsearch.helpers
from elasticsearch import Elasticsearch
# from elasticsearch import Elasticsearch, RequestsHttpConnection

es_host = '<>'
es_port = '<>'
es_username = '<>'
es_password = '><'
es_index = '<>'

es = Elasticsearch([{'host':str(es_host),'port':str(es_port)}], http_auth=(str(es_username), str(es_password)))

es.indices.refresh(index=es_index)

错误-

代码语言:javascript
运行
复制
10 es = Elasticsearch([{'host': str(es_host), 'port': str(es_port)}],http_auth=(str(es_username), str(es_password)))
     11 
     12 es.indices.refresh(index=es_index)

3 frames
/usr/local/lib/python3.7/dist-packages/elasticsearch/_sync/client/__init__.py in __init__(self, hosts, cloud_id, api_key, basic_auth, bearer_auth, opaque_id, headers, connections_per_node, http_compress, verify_certs, ca_certs, client_cert, client_key, ssl_assert_hostname, ssl_assert_fingerprint, ssl_version, ssl_context, ssl_show_warn, transport_class, request_timeout, node_class, node_pool_class, randomize_nodes_in_pool, node_selector_class, dead_node_backoff_factor, max_dead_node_backoff, serializer, serializers, default_mimetype, max_retries, retry_on_status, retry_on_timeout, sniff_on_start, sniff_before_requests, sniff_on_node_failure, sniff_timeout, min_delay_between_sniffing, sniffed_node_callback, meta_header, timeout, randomize_hosts, host_info_callback, sniffer_timeout, sniff_on_connection_fail, http_auth, maxsize, _transport)

/usr/local/lib/python3.7/dist-packages/elasticsearch/_sync/client/utils.py in client_node_configs(hosts, cloud_id, **kwargs)

/usr/local/lib/python3.7/dist-packages/elasticsearch/_sync/client/utils.py in hosts_to_node_configs(hosts)

/usr/local/lib/python3.7/dist-packages/elasticsearch/_sync/client/utils.py in host_mapping_to_node_config(host)

TypeError: __init__() missing 1 required positional argument: 'scheme'

当我加上“计划”

密码-

代码语言:javascript
运行
复制
es = Elasticsearch([{'host':str(es_host),'port':str(es_port)}], http_auth=(str(es_username), str(es_password)), scheme="http",verify_certs=False)

错误-

代码语言:javascript
运行
复制
__init__() got an unexpected keyword argument 'scheme'

我检查并尝试连接到ES,但它没有连接。

EN

回答 3

Stack Overflow用户

发布于 2022-05-24 11:08:06

根据Elasticsearch python库,对于安装在计算机上的不同版本的Elasticsearch,您必须有一个兼容的python库。例如,在我的例子中,我安装了ElasticSearchVersion7.17.3,我必须从PyPI安装相同的版本,可以用以下命令安装:

代码语言:javascript
运行
复制
pip install elasticsearch==7.17.3

此外,您还可以通过查看这个页面来检查python库的版本。

票数 4
EN

Stack Overflow用户

发布于 2022-07-18 02:53:45

我也遇到了一个类似的错误。我正在使用elasticsearch==8.3.1。当使用字典列表构造url时,需要定义模式。将"scheme": "https"添加到字典中,这将解决缺少的参数。

代码语言:javascript
运行
复制
es = Elasticsearch(
    [
        {'host': 'localhost', 'port': '9200', "scheme": "https"}
    ],
        basic_auth=('elastic', '<password>')
)

在这种情况下,您应该将实例化转换为如下所示:

代码语言:javascript
运行
复制
es = Elasticsearch(
    [
        {
            'host':str(es_host),
            'port':str(es_port),
            'scheme': "https"
        }
    ], 
    http_auth=(str(es_username), str(es_password))
)

我不确定该方案是http还是https,这是您需要深入研究的内容。

票数 3
EN

Stack Overflow用户

发布于 2022-05-17 13:02:09

您试图连接的Elasticsearch的版本是什么?

我也犯了同样的错误,因为我试图用python v8连接到Elasticsearch v8。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71622869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档