I'm hooking a python script up to run with cron (on Ubuntu 12.04) -- easy enough. Except for authentication.
The cron script accesses a couple services, and has to provide credentials. Storing those credentials with keyring
is easy as can be -- except that when the cron job actually runs, the credentials can't be retrieved. The script fails out every time.
As nearly as I can tell, this has something to do with the environment cron runs in. I tracked down a set of posts which suggest that the key is having the script export DBUS_SESSION_BUS_ADDRESS. All well and good -- I can get that address and, export it, and source it from Python fairly easily -- but it simply generates a new error: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
. Setting DISPLAY=:0
has no effect.
So. Has anybody figured out how to unlock gnome-keyring from Python running on a cron job on Ubuntu 12.04?
I'm sorry to say I don't have the answer, but I think I know a bit of what's going on based on an issue I'm dealing with. I'm trying to get a web application and cron script to use some code that stashes an oauth token for Google's API into a keyring using python-keyring.
No matter what I do, something about the environment the web app and cron job runs in requires manual intervention to unlock the keyring. That's quite impossible when your code is running in a non-interactive session. The problem persists when trying some tricks suggested in my research, like giving the process owner a login password that matches the keyring password and setting the keyring password to an empty string.
I will almost guarantee that your error stems from Gnome-Keyring trying to fire up an interactive (graphical) prompt and bombing because you can't do that from cron.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With