我有一个Python脚本,可通过HTTP以json格式下载数据。如果我使用请求模块通过命令行运行脚本,则HTTP连接成功,并且下载数据没有任何问题。但是,当我尝试将脚本作为crontab作业启动时,HTTP连接会在一段时间后引发超时。谁能告诉我这是怎么回事?我目前正在首先通过bash脚本下载数据,然后从该bash中运行Python脚本。但这是胡说!非常感谢!
使用:3.6.1 | Anaconda自定义(64位)| (默认值,2017年5月11日,13:09:58)\ n [GCC 4.4.7 20120313(Red Hat 4.4.7-1)]
PS:我还没有找到有关此问题的任何帖子。如果在其他帖子上已经对此有答案,请接受我的歉意。
这是我的代码的摘录。运行request.get(url)时超时:
try:
response = requests.get(url)
messages = response.json()["Messages"]
except requests.exceptions.Timeout:
logging.critical("TIMEOUT received when connecting to HTTP server.")
except requests.exceptions.ConnectionError:
logging.critical("CONNECTION ERROR received when connecting to HTTP server.")
Run Code Online (Sandbox Code Playgroud)