Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication works locally but not on server #814

Open
Mardiff opened this issue May 30, 2022 · 8 comments
Open

Authentication works locally but not on server #814

Mardiff opened this issue May 30, 2022 · 8 comments
Labels

Comments

@Mardiff
Copy link

Mardiff commented May 30, 2022

Describe the bug
I've managed to get authentication working locally with caches. Essentially, I have an HTML form that calls the following line on submit:
sp = spotipy.Spotify( auth_manager=spotipy.SpotifyOAuth(username=spotify_username, scope=ALL_SCOPES, cache_path=f"./caches/{spotify_username}"))
This works fine when running my Flask app locally with Flask run, with my redirect URI set to http://localhost:8080/. However, with the same code, I am unable to get it working on a web server (speciflcally gunicorn inside a Heroku job).

With my redirect URI set to anything that doesn't contain a port, I get an EOF error since Spotipy is waiting for user input. That's fine. But when I include a port, like in http://localhost:8080/, the server lags for a while and then throws a [CRITICAL] WORKER TIMEOUT. Is it because I'm using gunicorn? Is that a known issue? Why else would this fail on a Heroku server when it works fine on my local server?

@Mardiff Mardiff added the bug label May 30, 2022
@Peter-Schorn
Copy link
Contributor

Peter-Schorn commented Jun 11, 2022

You need to change your redirect URI to a URL on your server. You can't use http://localhost:8080/ (with any port number).

See https://github.com/plamere/spotipy/blob/master/examples/app.py

@Mardiff
Copy link
Author

Mardiff commented Jun 15, 2022

My goal was to have other users authenticate on their own, but that doesn't seem to be possible, right?

From what I can tell, localhost and 127.0.0.1 can only be used running the servers locally (which makes sense), so if I were to use another URL, it goes to interactive authentication, which requires input to the terminal, which I don't have because Heroku is a non-interactive terminal.

It appears I'm at a standstill. Perhaps this is now a feature request, then - either a way to perform non-interactive authentication for other users to use, or a way for interactive authentication to not require terminal input.

@itsa-mee-mario
Copy link

any updates? im trying the same

@stephanebruckert
Copy link
Member

stephanebruckert commented Jun 29, 2022

@itsa-mee-mario, @Mardiff, you have a full example here that lets multiple users authenticate via a non-local webserver https://github.com/plamere/spotipy/blob/master/examples/app.py

@itsa-mee-mario
Copy link

itsa-mee-mario commented Jun 29, 2022

@stephanebruckert hi, I seem to be having a problem similar to @Mardiff
im getting this in the logs

2022-06-29 19:50:00,749: Opened https://accounts.spotify.com/authorize?client_id=####removed client id####&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080&scope=user-top-read in your browser

i want the user to log into spotify, thatd need this url to be opened on the client side, is there any way to do that?

@stephanebruckert
Copy link
Member

Your SPOTIPY_REDIRECT_URI would need to be changed to http://example.com both in "code" and in the spotify app settings, have you tried that?

@itsa-mee-mario
Copy link

getting another error saying

 module 'spotipy.cache_handler' has no attribute 'FlaskSessionCacheHandler'

@itsa-mee-mario
Copy link

Your SPOTIPY_REDIRECT_URI would need to be changed to http://example.com both in "code" and in the spotify app settings, have you tried that?

yes have done that, put the same application uri as a redirect uri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants