【发布时间】:2020-02-14 05:33:00
【问题描述】:
我正在为物联网设备编写一个 python 脚本,其中涉及将一些数据发布到 API。该设备正在与本地无线网络上的某个节点进行通信,并在 4G 蜂窝网络上运行。
现在,如果存在互联网连接,设备将按预期工作并发布数据。但是如果设备没有连接到互联网,requests.post 调用会卡住很长一段时间,而在理想情况下,它应该会引发 requests.ConnectionError 例外。脚本的以下部分尝试发布数据。
try:
resp = requests.post(DATA_UPLOAD_API,json=postData,timeout=2)
except requests.ConnectionError as err:
self.logger.info("Failed to post the data with the exception-" + str(err) + "....trying again")
count=count+1
pass
它是否与本地无线网络有关,即使它不在线,它也会不断重试发布?如果不是这样,可能是什么问题?
【问题讨论】:
标签: python-3.x post python-requests