mental32 / spotify.py

🌐 API wrapper for Spotify 🎶
https://spotifypy.readthedocs.io/en/latest/
MIT License
150 stars 38 forks source link

Problem with OAuth scopes #16

Closed LorenzoCavatorta closed 5 years ago

LorenzoCavatorta commented 5 years ago

Hi!

I'm currently testing the Flask example for authenticating (I applied these two small changes, but everything else is a fresh clone from master, v 0.6.0). I'm getting an error from the OAuth module when trying to set up the scopes:

Traceback (most recent call last):
  File "spotify_test3.py", line 11, in <module>
    OAUTH2: spotify.OAuth2 = spotify.OAuth2(SPOTIFY_CLIENT.id, REDIRECT_URI, scopes=['user-modify-playback-state','user-read-currently-playing','user-read-playback-state'])
  File "/home/lollo/.local/share/virtualenvs/spotinator-I8qC83Ee/lib/python3.7/site-packages/spotify/oauth.py", line 105, in __init__
    self.set_scopes(**scopes)
  File "/home/lollo/.local/share/virtualenvs/spotinator-I8qC83Ee/lib/python3.7/site-packages/spotify/oauth.py", line 178, in set_scopes
    method = self.scopes.add if bool(state) else self.scopes.remove
  File "/home/lollo/.local/share/virtualenvs/spotinator-I8qC83Ee/lib/python3.7/site-packages/spotify/oauth.py", line 135, in scopes
    return MappingProxyType(self.__scopes)
TypeError: mappingproxy() argument must be a mapping, not set
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f1c7332d190>

In my case the scopes property is called with self.__scopes as a set (I don't see that attributed changing anywhere), but even if I call it with a dictionary, the MappingProxyType object will not have an .add (or .remove) method anyway. So I'm a bit lost

FYI: many things you're doing in your code are pretty new to me, so apologies for the dumb questions

LorenzoCavatorta commented 5 years ago

Hi, this is now working on v0.6.1 I am getting an "wrong scope" error on my request though. Given scope has to be a "[space separated list](space-separated list)" I changed line 143 to

data["scope"] = ' '.join([quote(scope.value) for scope in self.scopes])

and it's working

ghost commented 5 years ago

Any way I can install with this new fix?

mental32 commented 5 years ago

@Dextroz pip install git+https://github.com/mental32/spotify.py@v0.6.2#egg=spotify

micahdlamb commented 5 years ago

I believe you mistyped LorenzoCavatorta's fix and its erroring due to a list being passed into quote.

mental32 commented 5 years ago

@micahdlamb thanks for letting me know, I'll get a fix up in an hour or two

micahdlamb commented 5 years ago

Also I believe you want the " " chars passed into quote like: quote(" ".join(scope.value for scope in self.scopes)) Thanks so much for creating this project!

mental32 commented 5 years ago

Apologies for the lateness, I've made the changes and pushed 0.6.3 to pypi