所以我在python中有一个脚本,可以将推特发布到我的推特账号。我正在使用tweepy。
当我使用./run_my_script.py
或python run_my_script.py
手动运行脚本时,它工作得很好。
我试图通过cronjob运行它,无论我使用什么时间间隔(每分钟,每30分钟,每4小时等),我得到同样的错误:
错误发送请求失败:HTTPSConnectionPool(host ='api.twitter.com',port = 443):使用url超出最大重试次数:/1.1/statuses/update_with_media.json?status=information_related_to_my_tweet(由ConnectTimeoutError引发('连接到' api.twitter.com超时。(连接超时= 60)'))
有谁知道我有可能收到这个错误吗?我只是打电话
api.update_with_media(media, tweet)
一次在代码中。
我的crontab看起来像这样
PATH = "my_path_on_my_local_machine"
SHELL = "/bin/bash"
HOME = '/my/home/directory/goes/here"
*/30 * * * * cd the_directory_my_script_is_in && ./run_my_script.py
我是公司代理的幕后黑手。当我自己运行脚本以及为什么它不通过cron作业工作时它起作用的原因是因为我没有获取我的bash_profile并且连接不会通过代理。
我的crontab现在看起来像
*/30 * * * * cd the_directory_my_script_is_in && source ~/.bash_profile && ./run_my_script.py