[GH-ISSUE #814] Authentication works locally but not on server #506

Open
opened 2026-02-27 23:23:00 +03:00 by kerem · 8 comments
Owner

Originally created by @Mardiff on GitHub (May 30, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/814

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?

Originally created by @Mardiff on GitHub (May 30, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/814 **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?
Author
Owner

@Peter-Schorn commented on GitHub (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

<!-- gh-comment-id:1153014726 --> @Peter-Schorn commented on GitHub (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
Author
Owner

@Mardiff commented on GitHub (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.

<!-- gh-comment-id:1155945637 --> @Mardiff commented on GitHub (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.
Author
Owner

@itsa-mee-mario commented on GitHub (Jun 29, 2022):

any updates? im trying the same

<!-- gh-comment-id:1170403027 --> @itsa-mee-mario commented on GitHub (Jun 29, 2022): any updates? im trying the same
Author
Owner

@stephanebruckert commented on GitHub (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

<!-- gh-comment-id:1170405935 --> @stephanebruckert commented on GitHub (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
Author
Owner

@itsa-mee-mario commented on GitHub (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?

<!-- gh-comment-id:1170426083 --> @itsa-mee-mario commented on GitHub (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?
Author
Owner

@stephanebruckert commented on GitHub (Jun 29, 2022):

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?

<!-- gh-comment-id:1170430339 --> @stephanebruckert commented on GitHub (Jun 29, 2022): 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?
Author
Owner

@itsa-mee-mario commented on GitHub (Jun 29, 2022):

getting another error saying

 module 'spotipy.cache_handler' has no attribute 'FlaskSessionCacheHandler'
<!-- gh-comment-id:1170468178 --> @itsa-mee-mario commented on GitHub (Jun 29, 2022): getting another error saying ``` module 'spotipy.cache_handler' has no attribute 'FlaskSessionCacheHandler' ```
Author
Owner

@itsa-mee-mario commented on GitHub (Jun 29, 2022):

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

<!-- gh-comment-id:1170468530 --> @itsa-mee-mario commented on GitHub (Jun 29, 2022): > 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 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#506
No description provided.