python - 是什么导致 "elasticsearch.exceptions.ConnectionError: ConnectionError ... error(' getaddrinfo() argument 2 must be integer or string',)))

标签 python elasticsearch

用这个最少的代码:

import elasticsearch
es = elasticsearch.Elasticsearch([{u'host': u'127.0.0.1', u'port': u'9200'}])

# then do anything involving a connection, eg:
es.indices.exists_alias('foo')

我收到这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/johnc/.virtualenvs/myproject/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/home/johnc/.virtualenvs/myproject/local/lib/python2.7/site-packages/elasticsearch/client/indices.py", line 348, in exists_alias
    params=params)
  File "/home/johnc/.virtualenvs/myproject/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 276, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/home/johnc/.virtualenvs/myproject/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 51, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', error('getaddrinfo() argument 2 must be integer or string',))) caused by: ProtocolError(('Connection aborted.', error('getaddrinfo() argument 2 must be integer or string',)))

发生了什么事?

最佳答案

似乎 urllib3(至少版本 1.9)不喜欢将端口作为 unicode 字符串传入。将 port 更改为字节字符串或 int,修复此问题,即:

es = elasticsearch.Elasticsearch([{u'host': u'127.0.0.1', u'port': b'9200'}])

es = elasticsearch.Elasticsearch([{u'host': u'127.0.0.1', u'port': 9200}])

关于python - 是什么导致 "elasticsearch.exceptions.ConnectionError: ConnectionError ... error(' getaddrinfo() argument 2 must be integer or string',))),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24753569/

相关文章:

python - 在使用 Python 和 pypyodbc 的 Windows 上,如何列出可用的驱动程序?

ssl - 带有 SSL keystore 的 Logstash HTTP 输入

java - 使用JAVA API从Elastic Search建议搜索响应中提取源数据

elasticsearch - 使用nGram进行休眠搜索|如何指示nGram在搜索期间不赚钱

python - 如何使用属性获取lxml中所有元素的路径

python - 什么是 python 生成器?

python - 如何在 Python 的 argparse 中对同一组参数调用 parse_args() 两次?

python - 将四元数旋转应用于向量时间序列

amazon-web-services - 为什么我的新 AWS elasticsearch 总是黄色?

elasticsearch - 在 k8s pod 中运行 Logstash 需要哪些资源?