mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #492] Authentication hangs when ran in headless mode #294
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#294
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 @varna9000 on GitHub (May 17, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/492
Hi, I've got the latest release 2.12.0. My simple code is the following:
It seems the line
current_song = sp.currently_playing()hangs the code as it doesn't even raise an exception. I've tried calling other methods but it's the same result. Am I doing something wrong?@stephanebruckert commented on GitHub (May 17, 2020):
Since you need to sign in with your own spotify account via the browser, spotipy should have opened a browser window. So, bunch of questions:
spotipy currently hangs if the authentication response is not successful, which is something we might want to fix! But first let's try to make it for you
@varna9000 commented on GitHub (May 17, 2020):
Trouble is, I'm using headless Raspbian Lite install, so there's no browser and GUI. I thought that if all credentials match, including the redirect URI, all would be done automatically. Isn't that the case?
EDIT: Alternatively, if we can't avoid the browser, perhaps we can forward the url request to a console browser such as "links"?
@varna9000 commented on GitHub (May 17, 2020):
Ok, I installed Links and now it's automatically opened. The page is not showing correctly only in console, so I copied the url to my GUI browser and I saw the Spotify permission dialog. When I clicked "Agree" it redirects me to 127.0.0.1 (i.e. my Redirect URI), but naturally there is nothing there, since I opened it in another computer (with GUI). I thought that if you set localhost and 127.0.0.1 this Agree process is handled automatically. This was my impression from the docs, but apparently this is not the case.
@varna9000 commented on GitHub (May 17, 2020):
Phew, managed to do it, but it shouldn't be that hard. I set 127.0.0.1 as call-back URL (no port). "Links" browser automatically opened, I copied the URL (from processes list "ps ax") and pasted in GUI browser on another computer, clicked "Agree", then copied the full 127.0.0.1 redirect url, quit "Links" and pasted the url in the dialog prompt ("Enter the URL you were redirected to:") . Done. Quite a workaround.
@stephanebruckert commented on GitHub (May 17, 2020):
@nleroy917 commented on GitHub (May 25, 2020):
If you need a 100% headless mode, I've actually done this before with Spotify's client credentials flow. It uses selenium to drive a headless browser, insert the client credentials, and write the tokens to the environment, so you don't ever have to deal with typing in your credentials when running scripts.
I wrote it awhile ago - so it isn't the cleanest code, but it actually worked extremely well. It's here.
@varna9000 commented on GitHub (Jun 13, 2020):
@stephanebruckert
I would imagine, most people don't use headless installs but printing of the url would be of a huge help. Not sure I can contribute with a PR but will try.
@NLeRoy917 nice! I'll look into it.
@stephanebruckert commented on GitHub (Jun 13, 2020):
In fact this is how it was working in version 2.10.0; the URL was printed and it was prompting for the resulting URL. PR https://github.com/plamere/spotipy/pull/243 was merged to make that process automatic
Now I see 3 solutions for the headless mode:
use 2.10.0:
pip3 install 'spotipy~=2.10.0'keep the current version 2.12.0 and set a
REDIRECT_URIwithout any port, it will "magically" prompt for the URL (exactly what you need). More info in this PR https://github.com/plamere/spotipy/pull/477 and in the doc:(ideally) we could bring the manual mode back by adding a
headlessparameter (defaults toFalse) in theSpotifyOAuthconstructor:github.com/plamere/spotipy@587baec9b9/spotipy/oauth2.py (L200)and then check that it is not false in this conditiongithub.com/plamere/spotipy@587baec9b9/spotipy/oauth2.py (L373)such as:@smalls12 commented on GitHub (Jun 21, 2020):
I'm bumping into the same issue now re: headless mode.
Should I make make a separate PR to discuss and possibly implement your ideal solution above?