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',))
型
3条答案
按热度按时间q5lcpyga1#
NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f8f95d196d0>:无法建立新连接:[Errno -5] No address associated with hostname',))
这意味着您的计算机连接到的域名服务器(DNS)不知道给定的主机。
但是,如果我们检查域名,* 有 * 一个有效的IP地址。
字符串
因此,最有可能的错误是没有连接到互联网。因此,检查互联网连接是否正确设置(在运行代码的机器上,更具体地说,以便python可以使用它)。
更新
我的答案是指original question,其中提到了一个不同的域。现在问题中引用的域是未知的:
型
r1wp621o2#
似乎你的DNS服务器找不到一个地址相关联的URL你正在传递
thtygnil3#
重启电脑或互联网(我的解决方案)
嗨,看起来很奇怪,我在一台用“AnyDesk”程序处理的远程PC上遇到了同样的问题。在我使用AnyDesk与互联网连接的同时,互联网本身不工作,Firefox既不打开任何网站,也不请求Python库能够从任何网站获取信息,也不能从“www.example.com“获得任何ping答案google.com,就像如果anydesk在互联网配置中做了一些改变.我解决的问题重新启动远程pc.它现在的工作.(它正确地说,我的代码一直工作完美,直到昨天,没有碰任何东西,他们打破)
original en español y西班牙语:Tuve el mismo problema con una pc,de repente los codigos que abrian internet con“requests”,python的库,函数的调试,和“requests.exceptions.ConnectionError:HTTPConnectionPool(host ='es_search_demo. com',port=80):Max retries exceeded with url:“my_url”(Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f544af9a5d0>:Failed to establish a new connection:[Errno-2] Name or service not known ',))como esto era desde Odoo probé desde un terminal desde el root,tampoco funcionaba,probé el ping www.google.com,tampoco funcionaba,asique abri un navegador y vi que no habia internet(当我开始使用AnyDesk时,un poco desconcertado tener internet帕拉una cosa y no para el resto). Cuando descubrí esto solucion empecé a decidí por * reiniciar la pc*,y funcionó.