【问题标题】:CronTab(user=name) fails with TypeError: __init__() got an unexpected keyword argument 'user'CronTab(user=name) 失败并出现 TypeError: __init__() got an unexpected keyword argument 'user'
【发布时间】:2021-06-21 21:56:44
【问题描述】:

我已经通过“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')

【问题讨论】:

    标签: python linux automation cron python-3.6


    【解决方案1】:

    我认为您安装了crontab 而不是Python-crontab。这两个库共享同一个命名空间。

    要解决这个问题,您可以替换库:

    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()
    

    【讨论】:

    • 现在,它引发了一个像这样的新错误:- 文件“/home/hirensoni/.local/lib/python3.6/site-packages/crontab.py”,第 295 行,在读取raise IOError("Read crontab %s: %s" % (self.user, err)) OSError: Read crontab arpit: b"crontab: user `arpit' unknown\n" @Laurent
    • 如果它解决了你的问题,你可以接受这个答案。第二个问题是另一个问题:最好发布一个新问题。
    • @arpit_25,“arpit”不是你的用户名,不是吗?是“海伦索尼”吗?如果“arpit”是同一台机器上的另一个用户,您可能没有正确的访问权限和/或凭据。
    • "arpit" 是 /home/hirensoni/Documents/arpit @Laurent 下的文件夹名称
    • 所以,这不是你的用户名,替换为“hirensoni”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2015-02-21
    • 2021-06-11
    相关资源
    最近更新 更多