连接被拒绝是由于在请求连接尝试的数目,以限制

问题描述 投票:0回答:2

我有在Azure中物联网边缘运行一个脚本做一些计算,一旦该程序计算所需的数字,我把他们送到两个地方:

  • 回到物联网中心
  • 发布到本地URL与“要求” LIB

现在,这里的出现的问题,即;经过几天跑起来和精细的程序停止,日志显示了以下问题:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.5/dist-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/lib/python3.5/dist-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.5/http/client.py", line 1107, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line         181, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line     168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection         object at 0x6c05f6f0>: Failed to establish a new connection: [Errno 111]     Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
    File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.32.61', port=1880): Max retries exceeded with url: /camara (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x6c05f6f0>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/main.py", line 187, in <module>
    main()
  File "/app/main.py", line 161, in main
cameraCaptureSolver.start()
  File "/app/CameraCaptureSolver.py", line 161, in start
    requests.post('http://192.168.32.61:1880/camara', data = 'camaraName':camara})
  File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.32.61', port=1880): Max retries exceeded with url: /camara (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x6c05f6f0>: Failed to establish a new connection: [Errno 111] Connection refused',))

因此,问题是与请求,但不知道有在重试次数的限制。

如何删除或增加数量的任何想法?

python azure request azure-iot-hub
2个回答
1
投票

这不是一个完整的答案,甚至只是一个建议,做些什么的问题的方向。

至于你说“在重试次数的限制”,这是urllib3其重试次数默认为3的自动重试机制,作为官方文件低于所述。

Retrying requests

urllib3可以自动重试幂等请求。同样的机制也处理重定向。您可以使用重试参数要求控制重试()。默认情况下,urllib3将重试请求3次,随访至3个重定向。

您可以设置自定义的计数或禁用重试次数,如下面的代码。

http.request('GET', 'http://httpbin.org/ip', retries=10) // set 10 for reties
http.request('GET', 'http://nxdomain.example.com', retries=False) // disable retrying

对于错误ConnectionRefusedError,每次我的经验,有很多可能的原因,如:

  1. 运行不稳定的网络上,或在代理这是不是稳定的工作。
  2. 一些IoTHub限制或已过期的访问令牌原因拒绝连接问题。对于这种情况,您需要检查状态代码和相关错误信息,找出通过打印r.statusr.datar = http.request(...)的原因。

你可以参考IoT Hub limits的部分Azure subscription and service limits, quotas, and constraints到您的详细信息与这些限制相比,有IoT Hub及以下IoT Edge agentReference - IoT Hub quotas and throttling的错误代码,这将有助于你找出真正的原因。

图1.物联网中心enter image description here的常见错误

图2的IoT边缘剂的可能的响应发送到的IoT集线器enter image description here


0
投票

升级你的AWS订阅应该增加您可以发送请求的数量。

© www.soinside.com 2019 - 2024. All rights reserved.