[GH-ISSUE #572] How to get an OAuth token on a headless machine? #340

Closed
opened 2026-02-27 23:22:05 +03:00 by kerem · 1 comment
Owner

Originally created by @RaddedMC on GitHub (Sep 5, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/572

Hey there! I'm not sure if this is the right place to write about my issue, but I'm working on adding spotify integration to my SmartFrame infoboard using the Authorization code flow. The code works perfectly running on my desktop (ubuntu 20.04 LTS), but on my raspberry pi (zero w running dietpi) that is running the infoboard client, the code hangs when calling spotify.current_user_playing_track()
I've dug around and discovered that the problem is related to my raspberry pi being a headless machine, so there is no way for me to log into spotify via a web browser like how I did on my desktop, meaning spotipy is just hanging waiting for an OAuth token.
How would I get an OAuth token on my headless Raspberry PI? I've heard that I can host a web server on the pi but I've never hosted my own web server so I'm not sure where to start there. Would it be possible to copy/paste the OAuth token from my desktop to my rpi? I know that breaks like a million best practices but this is just for a personal project running on my home network and not for anything that's going to be publicly released.
Thanks for any and all help?

trimmed down code, appropriate try/catches and data collection are in my final code:

import spotipy

from spotipy.oauth2 import SpotifyOAuth

spotify_scope = "user-read-currently-playing"

spotify_user = #open a file and get my spotify username

spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=spotify_scope, redirect_uri="http://127.0.0.1:9090", 
cache_path=".spotifcache", client_id="MYID", client_secret="MYSECRET"))

current_track = spotify.current_user_playing_track() #This causes the code to hang

current_list =spotify.user_playlist(user=spotify_user, playlist_id=current_track["context"]["uri"], fields="name") #This never runs, trycatches are in place incase this returns nothing
Originally created by @RaddedMC on GitHub (Sep 5, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/572 Hey there! I'm not sure if this is the right place to write about my issue, but I'm working on adding spotify integration to my SmartFrame infoboard using the Authorization code flow. The code works perfectly running on my desktop (ubuntu 20.04 LTS), but on my raspberry pi (zero w running dietpi) that is running the infoboard client, the code hangs when calling spotify.current_user_playing_track() I've dug around and discovered that the problem is related to my raspberry pi being a headless machine, so there is no way for me to log into spotify via a web browser like how I did on my desktop, meaning spotipy is just hanging waiting for an OAuth token. How would I get an OAuth token on my headless Raspberry PI? I've heard that I can host a web server on the pi but I've never hosted my own web server so I'm not sure where to start there. Would it be possible to copy/paste the OAuth token from my desktop to my rpi? I know that breaks like a million best practices but this is just for a personal project running on my home network and not for anything that's going to be publicly released. Thanks for any and all help? trimmed down code, appropriate try/catches and data collection are in my final code: ```python import spotipy from spotipy.oauth2 import SpotifyOAuth spotify_scope = "user-read-currently-playing" spotify_user = #open a file and get my spotify username spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=spotify_scope, redirect_uri="http://127.0.0.1:9090", cache_path=".spotifcache", client_id="MYID", client_secret="MYSECRET")) current_track = spotify.current_user_playing_track() #This causes the code to hang current_list =spotify.user_playlist(user=spotify_user, playlist_id=current_track["context"]["uri"], fields="name") #This never runs, trycatches are in place incase this returns nothing ```
Author
Owner

@stephanebruckert commented on GitHub (Sep 7, 2020):

To solve this we need to do https://github.com/plamere/spotipy/issues/560

<!-- gh-comment-id:688312432 --> @stephanebruckert commented on GitHub (Sep 7, 2020): To solve this we need to do https://github.com/plamere/spotipy/issues/560
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#340
No description provided.