[GH-ISSUE #108] Run a spotipy script as cronjob on a Raspberry Pi (OAuth problem) #51

Closed
opened 2026-02-27 23:20:35 +03:00 by kerem · 5 comments
Owner

Originally created by @mymindwentblvnk on GitHub (Jul 27, 2016).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/108

Hi,

I tried to run my spotipy based python script on the Raspberry Pi. It won't work.
In the logs you will find the request for a new OAuth token ("... Paste that url you were directed to to complete the authorization.").

The spotipy cache file is also in the directory. The script works as long as I will not run it via CRON.

I cannot see how to solve this. Can somebody help me?

Greetings, michael

Originally created by @mymindwentblvnk on GitHub (Jul 27, 2016). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/108 Hi, I tried to run my spotipy based python script on the Raspberry Pi. It won't work. In the logs you will find the request for a new OAuth token ("... Paste that url you were directed to to complete the authorization."). The spotipy cache file is also in the directory. The script works as long as I will not run it via CRON. I cannot see how to solve this. Can somebody help me? Greetings, michael
kerem closed this issue 2026-02-27 23:20:35 +03:00
Author
Owner

@thedangler commented on GitHub (Aug 10, 2016):

I'm running into the same problem, it keeps asking me to authenticate even though I have. It's as if it doesn't get the cached token.

<!-- gh-comment-id:238865360 --> @thedangler commented on GitHub (Aug 10, 2016): I'm running into the same problem, it keeps asking me to authenticate even though I have. It's as if it doesn't get the cached token.
Author
Owner

@mymindwentblvnk commented on GitHub (Aug 10, 2016):

Does cron run with its own user?

<!-- gh-comment-id:238872619 --> @mymindwentblvnk commented on GitHub (Aug 10, 2016): Does cron run with its own user?
Author
Owner

@grlindburg commented on GitHub (Aug 10, 2016):

I believe cron runs as root. I set this up so that I'm cd'ing to the appropriate directory within cron before executing my spotipy script. Something like:

0 * * * * cd /env && /env/spotipy_script.py >> spotipy.log

Seems to work just fine for me since my appkey is also within this directory.

<!-- gh-comment-id:238895445 --> @grlindburg commented on GitHub (Aug 10, 2016): I believe cron runs as root. I set this up so that I'm cd'ing to the appropriate directory within cron before executing my spotipy script. Something like: `0 * * * * cd /env && /env/spotipy_script.py >> spotipy.log` Seems to work just fine for me since my appkey is also within this directory.
Author
Owner

@thedangler commented on GitHub (Aug 10, 2016):

Mine is working now, I was a moron and put , in between my scopes instead of leaving a space.
However, when I provide the full callback url it never works, If I provide ?code=.... it works. But I think it a pycharm console issue.

<!-- gh-comment-id:238910287 --> @thedangler commented on GitHub (Aug 10, 2016): Mine is working now, I was a moron and put , in between my scopes instead of leaving a space. However, when I provide the full callback url it never works, If I provide ?code=.... it works. But I think it a pycharm console issue.
Author
Owner

@mymindwentblvnk commented on GitHub (Aug 16, 2016):

Thanks @grlindburg
This worked for me too. My crontab task (every night at 0:24 AM)

24 0 * * * cd /home/pi/scripts/SpotifyNotificationTweeter && python3.4 main.py > /home/pi/snt.txt

<!-- gh-comment-id:240265086 --> @mymindwentblvnk commented on GitHub (Aug 16, 2016): Thanks @grlindburg This worked for me too. My crontab task (every night at 0:24 AM) `24 0 * * * cd /home/pi/scripts/SpotifyNotificationTweeter && python3.4 main.py > /home/pi/snt.txt`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#51
No description provided.