python crontab可以阅读sqlite3表
我正在处理一个Python Twitter机器人,该机器人在Python编辑器和Raspberry Pi的终端中运行良好,但是当我使用Cron运行它时,我会出现错误。
crontab文件:
* * * * * /home/eric/code/quotebot/quotebot.py >> /home/eric/code/quotebot/logs/minute.log 2>&1
错误消息:
Traceback (most recent call last):
File "/home/eric/code/quotebot/quotebot.py", line 22, in <module>
cursor.execute("SELECT MIN(countoftweets) FROM quotebot")
sqlite3.OperationalError: no such table: quotebot
因为从终端和IDE运行时它可以工作,所以我想知道权限是否有问题或我不知道的其他问题。该表绝对存在,数据库肯定存在。
I'm working on a Python Twitter bot that works fine in the Python editor and my Raspberry Pi's terminal, but when I run it using cron, I get an error.
crontab file:
* * * * * /home/eric/code/quotebot/quotebot.py >> /home/eric/code/quotebot/logs/minute.log 2>&1
Error message:
Traceback (most recent call last):
File "/home/eric/code/quotebot/quotebot.py", line 22, in <module>
cursor.execute("SELECT MIN(countoftweets) FROM quotebot")
sqlite3.OperationalError: no such table: quotebot
Because it works when running from the terminal and IDE, I'm wondering if there's an issue with permissions or something else I'm not aware of. The table definitely exists and the database definitely exists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这是您本地的用户crontab,则在脚本运行时,当前目录设置为您的主目录,
/home/eric
。您可能做了类似sqlite3.connect('quotebot.db')
之类的事情。该文件不存在,SQLite3很乐意为您创建一个新的空数据库。如果您需要家中的文件,则必须使用绝对路径,或者使用
os.path.dirname(__文件__)
来派生脚本的路径。If this is your local user crontab, then when the script runs, the current directory is set to your home directory,
/home/eric
. You probably did something likesqlite3.connect('quotebot.db')
. That file didn't exist, and sqlite3 is happy to create a new empty DB for you.If you need files outside of your home, you'll either have to use absolute paths, or derive the path of the script by using
os.path.dirname(__file__)
.