mental32 / spotify.py

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

TypeError: __await__() returned a coroutine #63

Closed jwelch1324 closed 3 years ago

jwelch1324 commented 3 years ago

When attempting to run the Flask example on the main README I get the following error

/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/spotify/models/user.py:199: RuntimeWarning: coroutine 'WrappedUser.__await__' was never awaited
  return await cls.from_token(client, token, refresh_token)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/spotify/models/user.py:199: RuntimeWarning: coroutine 'User.from_token.<locals>.constructor' was never awaited
  return await cls.from_token(client, token, refresh_token)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[2020-09-11 19:39:28,645] ERROR in app: Exception on /spotify/callback [GET]
Traceback (most recent call last):
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "test.py", line 30, in spotify_callback
    SPOTIFY_USERS[key] = spotify.User.from_code(
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/spotify/sync/models.py", line 45, in wrapped
    return self.__client_thread__.run_coroutine_threadsafe(
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/spotify/sync/thread.py", line 48, in run_coroutine_threadsafe
    return future.result()
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/Users/user/miniconda3/envs/env22/lib/python3.8/site-packages/spotify/models/user.py", line 199, in from_code
    return await cls.from_token(client, token, refresh_token)
TypeError: __await__() returned a coroutine

I am running the following python environment:

Python 3.8.5
spotify 0.10.2
flask 1.1.2
michaeldcanady commented 3 years ago

It seems that from_token is not async, I added that to the declaration. It fixed this issue but returns a Wrapper user object.

async def from_token(
        cls,
        client: "spotify.Client",
        token: Optional[str],
        refresh_token: Optional[str] = None,
    ) -> WrappedUser:
bmeares commented 3 years ago

I opened (my first ever) PR #68 where I removed await from return await cls.from_token(client, token, refresh_token) in User.from_code. Now await spotify.User.from_code(...) seems to work for me in FastAPI and Flask.