ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – 什么原因导致“elasticsearch.exceptions.ConnectionError:ConnectionError … error(‘getaddrinfo()参数2必

2019-08-25 02:57:01  阅读:94  来源: 互联网

标签: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字符串传入的端口.将端口更改为字节字符串或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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有