gpt4 book ai didi

python - 建立新连接失败

转载 作者:行者123 更新时间:2023-12-05 09:19:57 26 4
gpt4 key购买 nike

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',))

最佳答案

NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f8f95d196d0>: Failed to establish a new connection: [Errno -5] No address associated with hostname',))

这意味着您的计算机连接到的域名服务器 (DNS) 不知道给定的主机。

但是,如果我们检查它, 有一个带有域名的有效 IP 地址。

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

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

所以这个错误很可能意味着没有连接到互联网。因此,检查互联网连接是否正确设置(在运行代码的机器上,更具体地说,以便 python 可以使用它)。

更新

我的回答是指original question ,其中提到了不同的域。现在问题中引用的域未知:

$ nslookup es_search_demo.com
(...)

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

关于python - 建立新连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39064126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com