0

I'm trying to get the names of my top 3 artists of last week with pylast (https://github.com/pylast/pylast) but I run into an error or get I get None as a result and I don't see what I'm doing wrong. pylast is a Python interface to Last.fm.

My code:

import pylast

API_KEY = ""
API_SECRET = ""

username = ""
password_hash = pylast.md5("")

network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET, username=username, password_hash=password_hash)

user = network.get_authenticated_user();

weekly_artists = user.get_weekly_artist_charts();

# Keep the first three artists.
del weekly_artists[3:]

# Print the artist name and number of songs(weight).
for weekly_artist in weekly_artists:
  artist,weight = weekly_artist

  print (artist.get_name())
  print (artist.get_correction())

artist.get_name() returns

None

artist.get_correction() returns

Traceback (most recent call last):
  File "G:\projects\python\lastfm_weekly\lastfm-weekly.py", line 28, in <module>
    print (artist.get_correction())
  File "C:\Users\..\Python\Python36-32\lib\site-packages\pylast\__init__.py", line 1585, in get_correction
    self._request(self.ws_prefix + ".getCorrection"), "name")
  File "C:\Users\..\Python\Python36-32\lib\site-packages\pylast\__init__.py", line 1029, in _request
    return _Request(self.network, method_name, params).execute(cacheable)
  File "C:\Users\..\Python\Python36-32\lib\site-packages\pylast\__init__.py", line 744, in __init__
    network._get_ws_auth()
AttributeError: 'str' object has no attribute '_get_ws_auth'

What am I doing wrong?

Frenkieb
  • 11
  • 2
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. – Prune Mar 30 '18 at 20:39
  • Can you add more to this error message like line number etc? Can you also add all the imports you have? – Peter Dolan Mar 30 '18 at 20:39
  • I updated my question with the complete code and error message. – Frenkieb Mar 30 '18 at 21:25

1 Answers1

0

Here is a quick and dirty solution, i'm sure someone will provide something better but i just installed the package to test and it works.

network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET)

artists = network.get_top_artists()
del artists[:3]

for i in artists:
    artist, weight = i

    print('Artist = {}. Weight = {}'.format(artist, weight))

I'm not really familiar with the package, I just installed it to help out with this but I do wonder what "get_name()" and "get_correction()" are as they're not in your provided code.

If they're not functions you created / are defined within your code then I'd look there for the problem.

Also, you're authenticating the user but the documentation explicitly states you don't need to unless you're writing data.

Bromira
  • 25
  • 5
  • Hi Bromira, yes...that works for network.get_top_artists(). But if you replace that with user.get_weekly_artist_charts() the artist variable containts None. – Frenkieb Mar 30 '18 at 21:39