0

I have a simple python script set to run via the crontab which keeps failing. The script utilizes the keyring package, installed through pip. I set up keyring and can run the script manually in the shell with no problem via 'python3 /home/matt/script.py'. When I test run the script in the cronitor shell (emulating what is happening when the cron job fires off), I get:

Traceback (most recent call last):
  File "/home/matt/script.py", line 3, in <module>
    password = keyring.get_password("system", "blahblahblah")
  File "/home/matt/.local/lib/python3.9/site-packages/keyring/core.py", line 55, in get_password
    return get_keyring().get_password(service_name, username)
  File "/home/matt/.local/lib/python3.9/site-packages/keyring/backends/fail.py", line 25, in get_password
    raise NoKeyringError(msg)
keyring.errors.NoKeyringError: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details.

After reading up on cron, I figured installing and setting up the keyring root would solve the problem, so I sudo su'd, did all the set up, and...the job still failed...

Strangely, if I run the job manually as root, it succeeds...It's just through the crontab that it fails, but isn't it the root user which executes cron jobs?

I've also tried specifying the path for keyring in the script with sys.append, but no change in the error.

Laanan
  • 9
  • 1
  • It is almost certain this is a different in your `PATH` variable between your interactive shell and the crontab environtent. See https://stackoverflow.com/tags/cron/info for some debugging tips. In the future please post such questions to http://unix.stackexchange.com . Stackoverflow is dedicating to helping with `if-then-else` programming questions. Good luck! – shellter Jan 25 '23 at 20:44
  • Having looked at [keyring](https://pypi.org/project/keyring/) I have an inkling that this may be DBUS related. Check roots environment variables for DBUS, and output ENV from the python script when run via cron ... – tink Jan 26 '23 at 02:17

0 Answers0