[GH-ISSUE #995] EOFError: EOF when reading a line/ Enter the URL you were redirected to: 127.0.0.1 #590

Closed
opened 2026-02-27 23:23:31 +03:00 by kerem · 2 comments
Owner

Originally created by @Avishkar15 on GitHub (Jun 19, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/995

I keep getting

EOFError: EOF when reading a line
Jun 19 04:57:21 PM Enter the URL you were redirected to: 127.0.0.1
when I try to deploy my app from render

My callback function:
@app.route('/callback')
def callback():
cache_handler = spotipy.cache_handler.FlaskSessionCacheHandler(session)
auth_manager = spotipy.oauth2.SpotifyOAuth(scope=SPOTIPY_SCOPE, cache_handler=cache_handler, show_dialog=True)
if request.args.get("code"):
# Step 2. Being redirected from Spotify auth page
auth_manager.get_access_token(request.args.get("code"))
return redirect('/callback')

if not auth_manager.validate_token(cache_handler.get_cached_token()):
    # Step 1. Display sign in link when no token
    auth_url = auth_manager.get_authorize_url()
    redirect(auth_url)

# Step 3. Signed in, display data
sp = spotipy.Spotify(auth_manager=auth_manager)
top_genres = topgenres()
top_songs = get_top_songs()
user_info = sp.current_user()
user_name = user_info['display_name']
return render_template('app/genre.html', context=top_genres, user_name=user_name, songs=top_songs)

and my redirect uri is also set properly

Originally created by @Avishkar15 on GitHub (Jun 19, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/995 I keep getting EOFError: EOF when reading a line Jun 19 04:57:21 PM Enter the URL you were redirected to: 127.0.0.1 when I try to deploy my app from render My callback function: @app.route('/callback') def callback(): cache_handler = spotipy.cache_handler.FlaskSessionCacheHandler(session) auth_manager = spotipy.oauth2.SpotifyOAuth(scope=SPOTIPY_SCOPE, cache_handler=cache_handler, show_dialog=True) if request.args.get("code"): # Step 2. Being redirected from Spotify auth page auth_manager.get_access_token(request.args.get("code")) return redirect('/callback') if not auth_manager.validate_token(cache_handler.get_cached_token()): # Step 1. Display sign in link when no token auth_url = auth_manager.get_authorize_url() redirect(auth_url) # Step 3. Signed in, display data sp = spotipy.Spotify(auth_manager=auth_manager) top_genres = topgenres() top_songs = get_top_songs() user_info = sp.current_user() user_name = user_info['display_name'] return render_template('app/genre.html', context=top_genres, user_name=user_name, songs=top_songs) and my redirect uri is also set properly
kerem 2026-02-27 23:23:31 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Kudzmat commented on GitHub (Jul 1, 2023):

Hey, did you add the redirect URI as an environmental variable? The Authorization Code Flow needs you to add a redirect URI to your application on your app dashboard and then this needs to be set during authorization. I think you're getting that error because it can't find the redirect URI when you create the Spotify object. Here is an example:

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id= "your client id",
client_secret= "your client secret",
redirect_uri="http://localhost:8080",
scope="your scopes"))

You can read more about it in the documentation: https://spotipy.readthedocs.io/en/2.22.1/#authorization-code-flow
I hope this was helpful to you.

<!-- gh-comment-id:1615932709 --> @Kudzmat commented on GitHub (Jul 1, 2023): Hey, did you add the redirect URI as an environmental variable? The Authorization Code Flow needs you to add a redirect URI to your application on your app dashboard and then this needs to be set during authorization. I think you're getting that error because it can't find the redirect URI when you create the Spotify object. Here is an example: sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id= "your client id", client_secret= "your client secret", redirect_uri="http://localhost:8080", scope="your scopes")) You can read more about it in the documentation: https://spotipy.readthedocs.io/en/2.22.1/#authorization-code-flow I hope this was helpful to you.
Author
Owner

@dieser-niko commented on GitHub (Aug 22, 2024):

Closing as there is no activity or reply from the author.

<!-- gh-comment-id:2305935837 --> @dieser-niko commented on GitHub (Aug 22, 2024): Closing as there is no activity or reply from the author.
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#590
No description provided.