类型错误:__init__()缺少1个必需的位置参数:ElasticSearch中的“scheme”

56lgkhnf  于 2022-11-02  发布在  ElasticSearch
关注(0)|答案(3)|浏览(187)

下面是我的代码-
Elasticsearch没有使用https协议,而是使用http协议。

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)

错误-

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'

当我加上“方案”
代码-

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

错误-

__init__() got an unexpected keyword argument 'scheme'

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

5f0d552i

5f0d552i1#

根据Elasticsearch python library,对于安装在机器上的不同版本的Elasticsearch,你必须有一个兼容的python Elasticsearch库。例如,在我的例子中,我安装了Elasticsearch版本7.17.3,我必须从PyPI安装相同的版本,可以用下面的命令安装:

pip install elasticsearch==7.17.3

此外,您可以通过查看此页面来查看python Elasticsearch库的可用版本。

h9a6wy2h

h9a6wy2h2#

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

es = Elasticsearch(
    [
        {'host': 'localhost', 'port': '9200', "scheme": "https"}
    ],
        basic_auth=('elastic', '<password>')
)

在您的情况下,您应该将执行严修化转换为,如下所示:

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

我不确定这个方案是http还是https,这是你需要深入研究的问题。

fdbelqdn

fdbelqdn3#

您尝试连接的Elasticsearch版本是什么?
我遇到了同样的错误,来自尝试连接到Elasticsearch v7与python客户端v8。

相关问题