我正在处理一个小项目,我尝试使用他们给我的网址将传感器节点的json数据发送到服务器。它工作了几天直到今天,它一直说('连接中止。',错误(110,'连接超时'))。我在同一个网络上有几个节点,所有节点都无法发送。我尝试使用不同网络和ISP上的节点将数据发送到服务器,并且它成功了。
我使用pythonv2.7并请求lib版本:2.4.3
这是代码:
import time
import requests
headers = {'content-type': 'application/json'}
url = 'http://czwxxx.org/pxxx_API/v1/node1'
MAC = "v0 v0 v0 v0 v0 v0"
time = int(round(time.time()*1000))
data = {"MAC":MAC,"time":time,"x_raw":'0',"y_raw":'0',"z_raw":'0','status':'1'}
requests.post(url,data=data)
这是追溯
sudo python test.py
Traceback (most recent call last):
File "test.py", line 11, in <module>
requests.post(url,data=data)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 94, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 407, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(110, 'Connection timed out'))
我尝试设置iptables接受所有流量,但无济于事。以下是输出
sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
检查netstat -pn | grep:80它似乎陷入了SYN_SENT并且没有收到回复?
sudo netstat -pn|grep :80
tcp 0 1 192.168.8.104:34856 166.62.28.86:80 SYN_SENT 13751/python
我不确定问题是在我的互联网,节点配置还是防火墙中。我对此很陌生。任何帮助将不胜感激。
答案 0 :(得分:0)
我在Jenkins中有类似的问题,并且肯定与服务器上的python有关。请确保您在运行它的服务器上安装了兼容版本的python和唯一版本的python。希望这会有所帮助。