我有一个简单的python脚本,可以使用requests lib进行POST操作。在windows中,它运行良好,没有问题。在Linux中,即使我可以ping,它也不起作用。在Linux中,脚本提供了:
Traceback (most recent call last):
File "temp.py", line 55, in <module>
r = requests.post(urlPOST, json=payLoad, auth=('admin', 'pass'), verify=False)
File "/opt/ute/python/lib/python2.7/site-packages/requests/api.py", line 109, in post
return request('post', url, data=data, json=json, **kwargs)
File "/opt/ute/python/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/opt/ute/python/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/opt/ute/python/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/opt/ute/python/lib/python2.7/site-packages/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(110, 'Connection timed out'))
同样,我可以在Linux中对站点进行ping操作,没有任何问题。
问题:1-我怎么了?
2-是否有其他方法检查连接而不是ping?我是说,如果是代理问题,那么我也不能ping,对吧?
最佳答案
我的猜测是,网站没有回应你的请求,这就是为什么你得到一个超时错误。我将尝试通过更改标题中的用户代理来解决这个问题,因为有些网站可能试图避免机器人程序。也许可以试试这样的:
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebK it/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
r = requests.post(urlPOST, headers=header, json=payLoad, auth=('admin', 'pass'), verify=False)