spotipy-dev / spotipy

A light weight Python library for the Spotify Web API
http://spotipy.readthedocs.org
MIT License
5.03k stars 957 forks source link

EOFError: EOF when reading a line/ Enter the URL you were redirected to: 127.0.0.1 #995

Closed Avishkar15 closed 2 months ago

Avishkar15 commented 1 year ago

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

Kudzmat commented 1 year ago

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.

dieser-niko commented 2 months ago

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