[GH-ISSUE #118] Connection refused when trying to run a auth example. #55

Closed
opened 2026-02-27 23:20:37 +03:00 by kerem · 10 comments
Owner

Originally created by @c0nn3r on GitHub (Sep 23, 2016).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/118

After a night of debugging, I am convinced that something is wrong here. I am running the example that tries to get a user's shared tracks:

import sys
import spotipy
import spotipy.util as util

scope = 'user-library-read'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username, scope)

if token:
    sp = spotipy.Spotify(auth=token)
    results = sp.current_user_saved_tracks()
    for item in results['items']:
        track = item['track']
        print track['name'] + ' - ' + track['artists'][0]['name']
else:
    print "Can't get token for", username

My callback URL is https://localhost:8888/callback/, when I run the program it quickly redirects me to a URL with a code attached, but when I copy it into the prompt in the program I get an error.

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='accounts.spotify.com', port=443): Max retries exceeded with url: /api/token (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10b5d8650>: Failed to establish a new connection: [Errno 61] Connection refused',))

I'm not sure what is going on as I directly copied my program ID, the program callback url and my program's secret right into the env variables.

Any help fixing this problem would be appreciated.

Originally created by @c0nn3r on GitHub (Sep 23, 2016). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/118 After a night of debugging, I am convinced that something is wrong here. I am running the example that tries to get a user's shared tracks: ``` python import sys import spotipy import spotipy.util as util scope = 'user-library-read' if len(sys.argv) > 1: username = sys.argv[1] else: print "Usage: %s username" % (sys.argv[0],) sys.exit() token = util.prompt_for_user_token(username, scope) if token: sp = spotipy.Spotify(auth=token) results = sp.current_user_saved_tracks() for item in results['items']: track = item['track'] print track['name'] + ' - ' + track['artists'][0]['name'] else: print "Can't get token for", username ``` My callback URL is https://localhost:8888/callback/, when I run the program it quickly redirects me to a URL with a code attached, but when I copy it into the prompt in the program I get an error. ``` requests.exceptions.ConnectionError: HTTPSConnectionPool(host='accounts.spotify.com', port=443): Max retries exceeded with url: /api/token (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10b5d8650>: Failed to establish a new connection: [Errno 61] Connection refused',)) ``` I'm not sure what is going on as I directly copied my program ID, the program callback url and my program's secret right into the env variables. Any help fixing this problem would be appreciated.
kerem closed this issue 2026-02-27 23:20:37 +03:00
Author
Owner

@eugenio412 commented on GitHub (Sep 23, 2016):

Something wrong with the token, are you using a token enabled to get user saved tracks? You must add the right ticks generating the token on Spotify web API website

<!-- gh-comment-id:249222958 --> @eugenio412 commented on GitHub (Sep 23, 2016): Something wrong with the token, are you using a token enabled to get user saved tracks? You must add the right ticks generating the token on Spotify web API website
Author
Owner

@c0nn3r commented on GitHub (Sep 23, 2016):

I'm not sure what you mean, I generated my client ID and my client secret on https://developer.spotify.com/my-applications/#!/applications is this not the right place? Thanks for the response!

<!-- gh-comment-id:249223880 --> @c0nn3r commented on GitHub (Sep 23, 2016): I'm not sure what you mean, I generated my client ID and my client secret on `https://developer.spotify.com/my-applications/#!/applications` is this not the right place? Thanks for the response!
Author
Owner

@eugenio412 commented on GitHub (Sep 27, 2016):

I mean you need to add the right scope for the token

<!-- gh-comment-id:249833641 --> @eugenio412 commented on GitHub (Sep 27, 2016): I mean you need to add the right scope for the token
Author
Owner

@tahsinac commented on GitHub (Aug 16, 2018):

Wow, this is almost 2 years old now. Probably a shot in the dark, but did you manage to figure out (and remember) what it was that caused this error? I'm getting the exact same error.

<!-- gh-comment-id:413487367 --> @tahsinac commented on GitHub (Aug 16, 2018): Wow, this is almost 2 years old now. Probably a shot in the dark, but did you manage to figure out (and remember) what it was that caused this error? I'm getting the exact same error.
Author
Owner

@1llusion commented on GitHub (May 18, 2019):

Getting the same error. Seems to happen when there are repeatedly too many connections.

<!-- gh-comment-id:493707737 --> @1llusion commented on GitHub (May 18, 2019): Getting the same error. Seems to happen when there are repeatedly too many connections.
Author
Owner

@deekay2310 commented on GitHub (Oct 3, 2019):

Anyone with a solution? Experiencing the same error

<!-- gh-comment-id:538013779 --> @deekay2310 commented on GitHub (Oct 3, 2019): Anyone with a solution? Experiencing the same error
Author
Owner

@shillshocked commented on GitHub (Oct 23, 2019):

I'm getting this error too sometimes.

<!-- gh-comment-id:545268515 --> @shillshocked commented on GitHub (Oct 23, 2019): I'm getting this error too sometimes.
Author
Owner

@deekay2310 commented on GitHub (Oct 24, 2019):

Refreshed the access tokens and pasted the new one. It worked for me but it is more of a makeshift solution rather than a permanent one. Also, didn't experience the same issue after having pasted the new tokens.

<!-- gh-comment-id:545953533 --> @deekay2310 commented on GitHub (Oct 24, 2019): Refreshed the access tokens and pasted the new one. It worked for me but it is more of a makeshift solution rather than a permanent one. Also, didn't experience the same issue after having pasted the new tokens.
Author
Owner

@psl11 commented on GitHub (Feb 8, 2020):

Refreshed the access tokens and pasted the new one. It worked for me but it is more of a makeshift solution rather than a permanent one. Also, didn't experience the same issue after having pasted the new tokens.

OMG. It also worked for me, but don't know why... 🤦‍♂

<!-- gh-comment-id:583750368 --> @psl11 commented on GitHub (Feb 8, 2020): > Refreshed the access tokens and pasted the new one. It worked for me but it is more of a makeshift solution rather than a permanent one. Also, didn't experience the same issue after having pasted the new tokens. OMG. It also worked for me, but don't know why... 🤦‍♂
Author
Owner

@lawuysal commented on GitHub (May 21, 2023):

How to refresh it? I'm using flutter and I stuck where it comes from a authentication http request. Just shows localhost:8888/calback/code=...... and net:ERR_CONNECTION_REFUSED

<!-- gh-comment-id:1556297490 --> @lawuysal commented on GitHub (May 21, 2023): How to refresh it? I'm using flutter and I stuck where it comes from a authentication http request. Just shows localhost:8888/calback/code=...... and net:ERR_CONNECTION_REFUSED
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#55
No description provided.