I'm programming a script that returns your currently playing song from Spotify.
I read the documentation from Spotify API and everything is working well but I have some problems trying to implement some modules.
For example here https://spotipy.readthedocs.io/en/latest/ said that there's a module called currently_playing()
but I get this error:
Traceback (most recent call last):
File "spotify_test.py", line 21, in <module>
current_song = sp.currently_playing()
AttributeError: 'Spotify' object has no attribute 'currently_playing'
By far, this is my code, it works well when I change the scope and the module to obtain the playlists of a user. So the token is not the problem.
import sys
import spotipy
import spotipy.util as util
if len(sys.argv) > 1:
username = sys.argv[1]
else:
print('Usage %s Username ' % (sys.argv[0],))
sys.exit()
scope = 'user-read-currently-playing'
token = spotipy.util.prompt_for_user_token(
username, scope, redirect_uri='http://127.0.0.1/callback')
if token:
sp = spotipy.Spotify(auth=token)
current_song = sp.currently_playing()
else:
print("Can't get token for", username)
print(current_song)
Even if PyPi claims that the version of Spotipy is the latest there, 2.4.4, in fact, it is not. I noticed that after installing Spotipy with pip, its source code is different from the head of the master branch on the GitHub. And the PyPi version doesn't have the currently_playing
method.
What worked for me is to uninstall Spotipy by running pip uninstall spotipy
and to install it again directly from GitHub:
pip install git+https://github.com/plamere/spotipy.git@master