无法建立新连接

时间:2016-08-21 12:20:59

标签: python python-2.7 ubuntu-14.04

import requests

url = 'http://ES_search_demo.com/document/record/_search?pretty=true'
data = '{"query":{"bool":{"must":[{"text":{"record.document":"SOME_JOURNAL"}},{"text":{"record.articleTitle":"farmers"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}'
response = requests.get(url, data=data)

当我运行此代码时,我收到此错误

    Traceback (most recent call last):
  File "simpleclient.py", line 6, in <module>
    response = requests.get(url, data=data)
  File "/home/ryan/local/lib/python2.7/site-packages/requests/api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "/home/ryan/local/lib/python2.7/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/ryan/local/lib/python2.7/site-packages/requests/sessions.py", line 471, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/ryan/local/lib/python2.7/site-packages/requests/sessions.py", line 581, in send
    r = adapter.send(request, **kwargs)
  File "/home/ryan/local/lib/python2.7/site-packages/requests/adapters.py", line 481, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='es_search_demo.com', port=80): Max retries exceeded with url: /document/record/_search?pretty=true (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f544af9a5d0>: Failed to establish a new connection: [Errno -2] Name or service not known',))

2 个答案:

答案 0 :(得分:2)

  

NewConnectionError(':无法建立新连接:[Errno -5]没有与主机名关联的地址',))

换句话说,您的DNS没有给定主机的IP地址。 但是,由于有一个有效的IP地址,域名最初为,可能没有连接到互联网:

$ nslookup mmsdemo.cloudapp.net
(...)

Non-authoritative answer:
Name:   mmsdemo.cloudapp.net
Address: 40.113.108.105

换句话说,检查互联网连接是否设置正确(在运行代码的机器上,更具体地说,python可以使用它)。

<强>更新

最初给出的主机名与我的第一个答案相同。现在问题中的新域名证明了我的假设是正确的:

$ nslookup es_search_demo.com
(...)

** server can't find es_search_demo.com: NXDOMAIN

答案 1 :(得分:0)

似乎您的DNS服务器无法找到与您传递的网址相关联的地址