CronTab(user=name)失败,TypeError:\uuuu init\uuuuu()获得意外的关键字参数“user”

2024-04-29 09:02:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我通过“cron”尝试了这个脚本,但它向我显示了这样一个错误

from crontab import CronTab

my_cron = CronTab(user='arpit')
job = my_cron.new(command='/home/hirensoni/Documents/arpit/scrapping.py')
job.minute.every(1)

my_cron.write()

错误:

Exception has occurred: TypeError
__init__() got an unexpected keyword argument 'user'
  File "/home/hirensoni/Documents/arpit/regularautomation.py", line 3, in <module>
    my_cron = CronTab(user='arpit')

Tags: frompyimport脚本homemy错误job
1条回答
网友
1楼 · 发布于 2024-04-29 09:02:59

我想你已经安装了^{}而不是^{}。这两个库共享同一名称空间

要解决此问题,可以替换库:

pip uninstall crontab
pip install python-crontab

编辑

此外,请使用您的真实用户名

您的scrapping.py脚本必须是可执行的。最好使用实命令,例如/usr/local/bin/python your_script.py


from crontab import CronTab

my_cron = CronTab(user='hirensoni')
job = my_cron.new(command='/usr/local/bin/python /home/hirensoni/Documents/arpit/scrapping.py')
job.minute.every(1)

my_cron.write()

相关问题 更多 >