Python urllib3.exceptions.NewConnectionError连接自建API
Python urllib3.exceptions.NewConnectionError connecting to self-built API
我构建了一个 API(使用 flask-restful),它将数据存储在其缓存中并将其公开给其他应用程序。当我尝试从另一个应用程序(也是烧瓶)向此 API 发送获取请求时,它 returns 出现以下错误
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/usr/local/lib/python3.6/dist-packages/urllib3/util/connection.py", line 73, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 353, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 182, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f6f965d9358>: Failed to establish a new connection: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='data-collector.cloud', port=443): Max retries exceeded with url: /sample_url (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f6f965d9358>: Failed to establish a new connection: [Errno -2] Name or service not known',))
我认为发生此错误是因为我向 API 发送了太多具有相同 url 的请求。然后我通过添加限制了 API 调用的数量
decorators = [index.limiter.limit("60/minute")]
到 API。但是错误仍然存在。然后我想错误可能是服务器接受的调用量导致的。我以为我在进行 API 调用后没有正确关闭连接。所以我添加了
from requests.packages.urllib3 import Retry, PoolManager
retries = Retry(connect=5, read=2, redirect=5)
with PoolManager(retries=retries) as http:
response = http.request('GET', url)
但这也没有解决我的问题。我在这里错过了什么?我正在使用 python3.8
编辑: 我发现它本身并不是导致它的查询,因为如果我尝试其他查询,则会弹出相同的消息。我仍然不知道如何调试它:/
错误提示:“名称或服务未知”。换句话说,这是一个名称解析问题 (DNS)。
交叉检查目标主机(“data-collector.cloud”,它不在 public DNS 记录中。)
我构建了一个 API(使用 flask-restful),它将数据存储在其缓存中并将其公开给其他应用程序。当我尝试从另一个应用程序(也是烧瓶)向此 API 发送获取请求时,它 returns 出现以下错误
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/usr/local/lib/python3.6/dist-packages/urllib3/util/connection.py", line 73, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 353, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 182, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f6f965d9358>: Failed to establish a new connection: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='data-collector.cloud', port=443): Max retries exceeded with url: /sample_url (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f6f965d9358>: Failed to establish a new connection: [Errno -2] Name or service not known',))
我认为发生此错误是因为我向 API 发送了太多具有相同 url 的请求。然后我通过添加限制了 API 调用的数量
decorators = [index.limiter.limit("60/minute")]
到 API。但是错误仍然存在。然后我想错误可能是服务器接受的调用量导致的。我以为我在进行 API 调用后没有正确关闭连接。所以我添加了
from requests.packages.urllib3 import Retry, PoolManager
retries = Retry(connect=5, read=2, redirect=5)
with PoolManager(retries=retries) as http:
response = http.request('GET', url)
但这也没有解决我的问题。我在这里错过了什么?我正在使用 python3.8
编辑: 我发现它本身并不是导致它的查询,因为如果我尝试其他查询,则会弹出相同的消息。我仍然不知道如何调试它:/
错误提示:“名称或服务未知”。换句话说,这是一个名称解析问题 (DNS)。
交叉检查目标主机(“data-collector.cloud”,它不在 public DNS 记录中。)