Python/Linux Cron
我试图在Linux服务器上每隔5分钟运行一次TwitterPython脚本,当我通过SSH手动运行它时,它工作得非常好,但是当我尝试使用cron运行它时,我收到了这个错误消息Python/Linux Cron,python,linux,cron,server,Python,Linux,Cron,Server,我试图在Linux服务器上每隔5分钟运行一次TwitterPython脚本,当我通过SSH手动运行它时,它工作得非常好,但是当我尝试使用cron运行它时,我收到了这个错误消息 Traceback (most recent call last): File "/home/celestia/public_html/monroe/twitter_follow_bot.py", line 222, in <module> auto_follow("love",count=1)
Traceback (most recent call last):
File "/home/celestia/public_html/monroe/twitter_follow_bot.py", line 222, in <module>
auto_follow("love",count=1)
File "/home/celestia/public_html/monroe/twitter_follow_bot.py", line 108, in auto_follow
dnf_list.append(int(line))
ValueError: invalid literal for int() with base 10: ''
回溯(最近一次呼叫最后一次):
文件“/home/celestia/public\u html/monroe/twitter\u follow\u bot.py”,第222行,在
自动跟随(“爱”,计数=1)
文件“/home/celestia/public\u html/monroe/twitter\u follow\u bot.py”,第108行,自动跟踪
dnf_列表追加(整数(行))
ValueError:基数为10的int()的文本无效:“”
第108行是dnf_列表。追加(int(Line))
这是源代码
我的cron工作是这样的
*/5****/usr/local/bin/python2.7/home/celestia/public\u html/elvis/twitter\u follow\u bot.py尽可能多地发布有关问题的信息,包括代码,这一点很重要
行
的值为'
这可以通过在添加到列表之前检查行是否不是空字符串在程序中处理
if line:
dnf_list.append(int(line))
如果
行
不是一个数字,尽管您正在从文件后接的文件中读取一个空行,当您尝试将其转换为int
时,这会导致值错误
,上述操作仍然会出错。在下面的代码中,我捕获int转换失败的异常,这将解决您的问题
with open(ALREADY_FOLLOWED_FILE) as in_file:
for line in in_file:
try:
twitter_id = int(line)
except ValueError:
continue
else:
dnf_list.append(twitter_id)
文件“/home/celestia/public\u html/elvis/twitter\u follow\u bot.py”,文件中第107行:^IndentationError:应为缩进block@BradHouston删除额外空间