[GH-ISSUE #792] Using util.prompt_for_user_token on a headless machine, can't use open_browser=False? #490

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

Originally created by @kingofsquirrel on GitHub (Mar 20, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/792

Okay, so I've recently moved on to a Raspberry Pi although whenever I try to use Spotipy it gets stuck.
I figured out that the problem is that normally, a browser window would open so I can authenticate my program.
I'm now working on a headless machine so it of course doesn't work.
There has been an issue like this before and it was said that there was the variable open_browser added, which is exactly what I'm looking for.
Although with my method of authorisation, I can't use open browser?

The only pieces of code I have are

token = util.prompt_for_user_token(username=username,scope=scope, client_id=client_id_spotify, client_secret=client_secret_spotify, redirect_uri=redirect_uri)

and then

sp = spotipy.Spotify(auth=token)

The problem is that open_browser can't be used with util, and I have no idea how to get it working.

Originally created by @kingofsquirrel on GitHub (Mar 20, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/792 Okay, so I've recently moved on to a Raspberry Pi although whenever I try to use Spotipy it gets stuck. I figured out that the problem is that normally, a browser window would open so I can authenticate my program. I'm now working on a headless machine so it of course doesn't work. There has been an issue like this before and it was said that there was the variable open_browser added, which is exactly what I'm looking for. Although with my method of authorisation, I can't use open browser? The only pieces of code I have are `token = util.prompt_for_user_token(username=username,scope=scope, client_id=client_id_spotify, client_secret=client_secret_spotify, redirect_uri=redirect_uri)` and then `sp = spotipy.Spotify(auth=token)` The problem is that open_browser can't be used with util, and I have no idea how to get it working.
kerem 2026-02-27 23:22:55 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@stephanebruckert commented on GitHub (Dec 7, 2022):

spotipy.util.prompt_for_user_token() is deprecated and it is now recommended to use:

spotipy.Spotify(auth_manager=SpotifyOAuth(open_browser=False))

See https://github.com/spotipy-dev/spotipy/blob/master/examples/headless.py for an example

<!-- gh-comment-id:1341117877 --> @stephanebruckert commented on GitHub (Dec 7, 2022): `spotipy.util.prompt_for_user_token()` is deprecated and it is now recommended to use: spotipy.Spotify(auth_manager=SpotifyOAuth(open_browser=False)) See https://github.com/spotipy-dev/spotipy/blob/master/examples/headless.py for an example
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#490
No description provided.