[GH-ISSUE #314] Connection refused #179

Closed
opened 2026-02-27 23:21:14 +03:00 by kerem · 6 comments
Owner

Originally created by @SockworkOrange on GitHub (Jul 27, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/314

I did it by the book -

  1. I created an application in spotify
  2. exported the CLIENT_ID, CLIENT_SECRET & REDIRECT_URI (this one is http://localhost:8888/callback/ - as recommended)
  3. Added the redirect uri to the whitelisted addresses.

When I run my app I get the following message:

        User authentication requires interaction with your
        web browser. Once you enter your credentials and
        give authorization, you will be redirected to
        a url.  Paste that url you were directed to to
        complete the authorization.

Opened https://accounts.spotify.com/authorize?client_id=myclientid&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F&scope=user-follow-modify in your browser

Enter the URL you were redirected to:

and this message is of course accompanied by opening the this url, and this message appears:

This site can’t be reached
localhost refused to connect.
Search Google for localhost 8888 callback
ERR_CONNECTION_REFUSED

What am I doing wrong?

Originally created by @SockworkOrange on GitHub (Jul 27, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/314 I did it by the book - 1. I created an application in spotify 2. exported the CLIENT_ID, CLIENT_SECRET & REDIRECT_URI (this one is http://localhost:8888/callback/ - as recommended) 3. Added the redirect uri to the whitelisted addresses. When I run my app I get the following message: > User authentication requires interaction with your > web browser. Once you enter your credentials and > give authorization, you will be redirected to > a url. Paste that url you were directed to to > complete the authorization. > > > Opened https://accounts.spotify.com/authorize?client_id=*myclientid*&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F&scope=user-follow-modify in your browser > > > Enter the URL you were redirected to: and this message is of course accompanied by opening the this url, and this message appears: > This site can’t be reached > localhost refused to connect. > Search Google for localhost 8888 callback > ERR_CONNECTION_REFUSED What am I doing wrong?
kerem closed this issue 2026-02-27 23:21:14 +03:00
Author
Owner

@ritiek commented on GitHub (Jul 27, 2018):

You have to copy the URL you are redirected to and paste it in the terminal where it asks for (even if it says "This site can’t be reached", you still have to copy-paste the URL).

<!-- gh-comment-id:408489509 --> @ritiek commented on GitHub (Jul 27, 2018): You have to copy the URL you are redirected to and paste it in the terminal where it asks for (even if it says "This site can’t be reached", you still have to copy-paste the URL).
Author
Owner

@SockworkOrange commented on GitHub (Jul 27, 2018):

I copy it, presses enter and it opens the URL one more time - and the code afterwards just does not run.
This is the full code:

import sys
import spotipy
import spotipy.util as util
import glob
import re

if len(sys.argv) == 3:
    username = sys.argv[1]
else:
    sys.exit()

token = util.prompt_for_user_token(username=username, scope='user-follow-modify')

try :
    sp = spotipy.Spotify(auth=token)
    results = sp.current_user_saved_tracks()
    for item in results['items']:
        track = item['track']
        print(track)
except:
    print('Unable to connect to username ' + username)

It doesn't print any error or something - it just doesn't run...

<!-- gh-comment-id:408493151 --> @SockworkOrange commented on GitHub (Jul 27, 2018): I copy it, presses enter and it opens the URL one more time - and the code afterwards just does not run. This is the full code: ``` import sys import spotipy import spotipy.util as util import glob import re if len(sys.argv) == 3: username = sys.argv[1] else: sys.exit() token = util.prompt_for_user_token(username=username, scope='user-follow-modify') try : sp = spotipy.Spotify(auth=token) results = sp.current_user_saved_tracks() for item in results['items']: track = item['track'] print(track) except: print('Unable to connect to username ' + username) ``` It doesn't print any error or something - it just doesn't run...
Author
Owner

@omadume commented on GitHub (Apr 8, 2019):

Same issue is occurring for me

<!-- gh-comment-id:480874360 --> @omadume commented on GitHub (Apr 8, 2019): Same issue is occurring for me
Author
Owner

@jeremyreikes commented on GitHub (Sep 3, 2019):

+1

<!-- gh-comment-id:527554331 --> @jeremyreikes commented on GitHub (Sep 3, 2019): +1
Author
Owner

@aaron-freeman commented on GitHub (Sep 4, 2019):

Your code runs, it just must be executing the else statement.
Personally, I've had an easier time utilizing the Client Credentials Flow.

<!-- gh-comment-id:527719763 --> @aaron-freeman commented on GitHub (Sep 4, 2019): Your code runs, it just must be executing the `else` statement. Personally, I've had an easier time utilizing the [Client Credentials Flow](https://spotipy.readthedocs.io/en/latest/#client-credentials-flow).
Author
Owner

@stephanebruckert commented on GitHub (Jan 13, 2020):

CLIENT_ID, CLIENT_SECRET & REDIRECT_URI should be SPOTIPY_CLIENT_ID, SPOTIPY_CLIENT_SECRET and SPOTIPY_REDIRECT_URI. Also the previous versions were a bit buggy so make sure to upgrade:

pip install spotipy --upgrade
<!-- gh-comment-id:573898357 --> @stephanebruckert commented on GitHub (Jan 13, 2020): `CLIENT_ID,` `CLIENT_SECRET `& `REDIRECT_URI` should be `SPOTIPY_CLIENT_ID`, `SPOTIPY_CLIENT_SECRET` and `SPOTIPY_REDIRECT_URI`. Also the previous versions were a bit buggy so make sure to upgrade: pip install spotipy --upgrade
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#179
No description provided.