[GH-ISSUE #143] Exception on authorization #69

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

Originally created by @irskep on GitHub (Jan 2, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/143

I'm using Python 3.5. I ran the demo code, modified for Python 3:

#!/usr/bin/env python3.5

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: {} username".format(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)

But when I pasted the URL, I got this exception:



            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?response_type=code&scope=user-library-read&client_id=REDACTED&redirect_uri=http%3A%2F%2Flocalhost%3A3003 in your browser


Enter the URL you were redirected to: http://localhost:3003/?code=REDACTED


Traceback (most recent call last):
  File "./scrape.py", line 15, in <module>
    token = util.prompt_for_user_token(username, scope)
  File "/Users/steve/env/spotify-artist-scrape/lib/python3.5/site-packages/spotipy/util.py", line 86, in prompt_for_user_token
    token_info = sp_oauth.get_access_token(code)
  File "/Users/steve/env/spotify-artist-scrape/lib/python3.5/site-packages/spotipy/oauth2.py", line 214, in get_access_token
    headers=headers, verify=True, proxies=self.proxies)
AttributeError: 'SpotifyOAuth' object has no attribute 'proxies'
Originally created by @irskep on GitHub (Jan 2, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/143 I'm using Python 3.5. I ran the demo code, modified for Python 3: ```python3 #!/usr/bin/env python3.5 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: {} username".format(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) ``` But when I pasted the URL, I got this exception: ``` 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?response_type=code&scope=user-library-read&client_id=REDACTED&redirect_uri=http%3A%2F%2Flocalhost%3A3003 in your browser Enter the URL you were redirected to: http://localhost:3003/?code=REDACTED Traceback (most recent call last): File "./scrape.py", line 15, in <module> token = util.prompt_for_user_token(username, scope) File "/Users/steve/env/spotify-artist-scrape/lib/python3.5/site-packages/spotipy/util.py", line 86, in prompt_for_user_token token_info = sp_oauth.get_access_token(code) File "/Users/steve/env/spotify-artist-scrape/lib/python3.5/site-packages/spotipy/oauth2.py", line 214, in get_access_token headers=headers, verify=True, proxies=self.proxies) AttributeError: 'SpotifyOAuth' object has no attribute 'proxies' ```
kerem closed this issue 2026-02-27 23:20:41 +03:00
Author
Owner

@plamere commented on GitHub (Jan 2, 2017):

what version of requests do you have?

<!-- gh-comment-id:269996361 --> @plamere commented on GitHub (Jan 2, 2017): what version of requests do you have?
Author
Owner

@irskep commented on GitHub (Jan 2, 2017):

Here are the complete contents of my virtualenv:

requests==2.12.4
spotipy==2.4.2
<!-- gh-comment-id:269996438 --> @irskep commented on GitHub (Jan 2, 2017): Here are the complete contents of my virtualenv: ``` requests==2.12.4 spotipy==2.4.2 ```
Author
Owner

@irskep commented on GitHub (Jan 2, 2017):

Reading the code, it looks like SpotifyOAuth never has a "proxies" attribute assigned to it, yet it tries to access it in a couple of places.

<!-- gh-comment-id:269996648 --> @irskep commented on GitHub (Jan 2, 2017): Reading the code, it looks like `SpotifyOAuth` never has a "proxies" attribute assigned to it, yet it tries to access it in a couple of places.
Author
Owner

@plamere commented on GitHub (Jan 2, 2017):

it is working for me. It is assigned here:

https://github.com/plamere/spotipy/blob/master/spotipy/oauth2.py#L47

Maybe there's some version skew?

<!-- gh-comment-id:269996966 --> @plamere commented on GitHub (Jan 2, 2017): it is working for me. It is assigned here: https://github.com/plamere/spotipy/blob/master/spotipy/oauth2.py#L47 Maybe there's some version skew?
Author
Owner

@irskep commented on GitHub (Jan 2, 2017):

You linked to where it is assigned in SpotifyClientCredentials. The problem is it is used in SpotifyOAuth, where it does not exist.

<!-- gh-comment-id:269997044 --> @irskep commented on GitHub (Jan 2, 2017): You linked to where it is assigned in `SpotifyClientCredentials`. The problem is it is used in `SpotifyOAuth`, where it does not exist.
Author
Owner

@plamere commented on GitHub (Jan 2, 2017):

ah ok, I'll take a look, hang on

<!-- gh-comment-id:269997172 --> @plamere commented on GitHub (Jan 2, 2017): ah ok, I'll take a look, hang on
Author
Owner

@irskep commented on GitHub (Jan 2, 2017):

Note the exception is on line 214, which reads:

response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
    headers=headers, verify=True, proxies=self.proxies)

self.proxies does not exist on this class! If I remove the proxies= kwarg here and again on line 241, it works.

<!-- gh-comment-id:269997194 --> @irskep commented on GitHub (Jan 2, 2017): Note the exception is on line 214, which reads: ```python response = requests.post(self.OAUTH_TOKEN_URL, data=payload, headers=headers, verify=True, proxies=self.proxies) ``` `self.proxies` does not exist on this class! If I remove the `proxies=` kwarg here and again on line 241, it works.
Author
Owner

@plamere commented on GitHub (Jan 2, 2017):

ok, should be fixed now, thanks for the report!

<!-- gh-comment-id:269998119 --> @plamere commented on GitHub (Jan 2, 2017): ok, should be fixed now, thanks for the report!
Author
Owner

@irskep commented on GitHub (Jan 2, 2017):

No problem, thanks for the useful library and being on top of things!

<!-- gh-comment-id:269998157 --> @irskep commented on GitHub (Jan 2, 2017): No problem, thanks for the useful library and being on top of things!
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#69
No description provided.