mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #710] Can't get a token with Spotipy running with Kafka #423
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#423
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @giopri13 on GitHub (Jul 20, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/710
Hello everyone, I'm sorry to bother you with a question that has already been asked, but I have no clue on how to implement what I need.
I'm writing a script that retrieves the songs from the Top 50 Global playlist and sends a dictionary through Kafka. Locally, my script works because I could obtain the access token through the standard process of opening the browser and pasting the link.
The problem is that I need to run it within a docker container as a Kafka python app, so I can't really access a browser.
I tried both util.prompt_for_user_token() and oauth2.SpotifyClientCredentials().
The first option asks me to insert the URL I should have been redirected to, while the second one doesn't work with error "spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/37i9dQZEVXbMDoHDwVN2tF?additional_types=track:
Only valid bearer authentication supported, reason: None"
redirect_uri is the same as of My Developer Dashboard from Spotify.
Again, I'm sorry to ask such a question again (and also if I made any mistakes writing this).
Thank you for your attention.
Here's my code responsible for initializing Spotipy:
`
def init():
`
@smtchahal commented on GitHub (Aug 18, 2021):
@giopri13 Did you find a solution for this? I have the same problem.
@giopri13 commented on GitHub (Aug 18, 2021):
Hello @smtchahal, in the end I managed to make it work not by using util.prompt_for_user_token but with SpotifyOAuth and setting the flag open_browser=False.
I had already tried going that route before submitting this issue but apparently python didn't like the way I was separating lines of code and threw errors at me for not writing on a single line.
Here's my solution
# Initialize Spotify instance def init(): client_id = "xxx" client_secret = "xxx" scope = "" redirect_uri = "https://spotify.com" spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, scope=scope, open_browser=False)) return spotifyNow you'll be able to open manually the link for authorization and then paste your authorization code on the terminal
@smtchahal commented on GitHub (Aug 18, 2021):
SpotifyOAuthwithopen_browser=Falsedid the trick, many thanks! :)@Peter-Schorn commented on GitHub (Aug 18, 2021):
In order to authorize your app, you need to open the browser at least once. There's no way around that. Period. You can authorize your app the first time in a local script, and then save the token info in persistent storage, which you can make accessible from kafka. More specifically, after you authorize your app, a file called
.cachewill be created in the same directory as your script. This file contains the token info.