[GH-ISSUE #926] How to send someone a working authorize url? #554

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

Originally created by @Andrew3212 on GitHub (Jan 4, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/926

I'm trying to send .get_authorize_url across discord so a friend can authorize. It currently allows them to sign in, but after they do, it says This site can't be reached 127.0.0.1 refused to connect.
Then if they call the current song command on the discord bot it returns my song, not theirs.

async def csong(ctx):
    c.execute("SELECT sp FROM accounts WHERE id = {I}".format(I=ctx.user.id))     
    uid = c.fetchone()[0]
    auth_manager = spotipy.oauth2.SpotifyOAuth(scope='user-read-currently-playing', show_dialog=True, username=uid)
    await ctx.respond(auth_manager.get_authorize_url())
    token = spotipy.util.prompt_for_user_token(uid, scope='user-read-currently-playing', oauth_manager=auth_manager, show_dialog=True )
    sp = spotipy.Spotify(token)
Originally created by @Andrew3212 on GitHub (Jan 4, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/926 I'm trying to send .get_authorize_url across discord so a friend can authorize. It currently allows them to sign in, but after they do, it says **This site can't be reached** 127.0.0.1 refused to connect. Then if they call the current song command on the discord bot it returns my song, not theirs. ``` async def csong(ctx): c.execute("SELECT sp FROM accounts WHERE id = {I}".format(I=ctx.user.id)) uid = c.fetchone()[0] auth_manager = spotipy.oauth2.SpotifyOAuth(scope='user-read-currently-playing', show_dialog=True, username=uid) await ctx.respond(auth_manager.get_authorize_url()) token = spotipy.util.prompt_for_user_token(uid, scope='user-read-currently-playing', oauth_manager=auth_manager, show_dialog=True ) sp = spotipy.Spotify(token) ```
kerem 2026-02-27 23:23:18 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@stephanebruckert commented on GitHub (Jan 5, 2023):

If I remember correctly, it's fine to see This site can't be reached 127.0.0.1 refused to connect. All your friend needs to do is copy the URL at that point and send it to you (that URL contains a code), so that you can enter it in your terminal when you get Enter the URL you were redirected to and complete the authentication.

<!-- gh-comment-id:1371932589 --> @stephanebruckert commented on GitHub (Jan 5, 2023): If I remember correctly, it's fine to see `This site can't be reached 127.0.0.1 refused to connect`. All your friend needs to do is copy the URL at that point and send it to you (that URL contains a code), so that you can enter it in your terminal when you get `Enter the URL you were redirected to` and complete the authentication.
Author
Owner

@Andrew3212 commented on GitHub (Jan 8, 2023):

Ok now I'm calling this sp_oauth.get_authorize_url() and then in another function I send the url
code = ctx.options.URL token = sp_oauth.get_access_token(code=code, as_dict=False, check_cache=False)
But then it says this:
spotipy.oauth2.SpotifyOauthError: error: invalid_grant, error_description: Invalid authorization code

<!-- gh-comment-id:1374726330 --> @Andrew3212 commented on GitHub (Jan 8, 2023): Ok now I'm calling this `sp_oauth.get_authorize_url()` and then in another function I send the url `code = ctx.options.URL token = sp_oauth.get_access_token(code=code, as_dict=False, check_cache=False)` But then it says this: spotipy.oauth2.SpotifyOauthError: error: invalid_grant, error_description: Invalid authorization code
Author
Owner

@Andrew3212 commented on GitHub (Jan 8, 2023):

Just had to parse it! The bot is fully complete now :D

code = ctx.options.URL
code = sp_oauth.parse_response_code(code)
print(code)
token = sp_oauth.get_access_token(code=code, as_dict=False, check_cache=False)
<!-- gh-comment-id:1374731736 --> @Andrew3212 commented on GitHub (Jan 8, 2023): Just had to parse it! The bot is fully complete now :D ``` code = ctx.options.URL code = sp_oauth.parse_response_code(code) print(code) token = sp_oauth.get_access_token(code=code, as_dict=False, check_cache=False) ```
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#554
No description provided.