在尝试使用pylast中的library.add_track函数时,我需要帮助调试收到的错误。我检查了代码,但我不是python的专家。我只是想利用这个包装器向我的库添加一个轨道列表。你可以在这里找到pylast代码:
http://code.google.com/p/pylast/source/browse/trunk/pylast.py
import pylast
# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from http://www.last.fm/api/account for Last.fm
API_KEY = "your_key"
API_SECRET = "your_secret"
# In order to perform a write operation you need to authenticate yourself
username = "username"
password_hash = pylast.md5("password")
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)
# This is the area causing trouble
library1 = pylast.Library(user = "Username", network = "LastFM")
track1 = network.get_track("Rob Dougan", "Clubbed To Death (Kurayamino Variation)")
library1.add_track(track1)
我收到的错误是:
Traceback (most recent call last):
File "addTrack.py", line 18, in <module>
library1.add_track(track1)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 1976, in add_track
self._request("library.addTrack", False, params)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 970, in _request
return _Request(self.network, method_name, params).execute(cacheable)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 715, in __init__
(self.api_key, self.api_secret, self.session_key) = network._get_ws_auth()
AttributeError: 'str' object has no attribute '_get_ws_auth'
我很感激帮助。
更新
对于有pylast问题的其他人,我将在下面发布一个正确的示例,用于向库中添加曲目。我将错误的网络参数传递给pylast.Library()。
修复上述问题后,代码开始抛出缺少的参数错误。我必须在Library类的add_track()函数中添加以下行到pylast.py(第1970行)。这是Last.fm API的必要参数。
params['artist'] = track.get_artist().get_name()
将曲目添加到用户库的工作示例:
import pylast
# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from http://www.last.fm/api/account for Last.fm
API_KEY = "your_key"
API_SECRET = "your_secret"
# In order to perform a write operation you need to authenticate yourself
username = "username"
password_hash = pylast.md5("password")
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)
# Get the User's library
library = pylast.Library(user = "username", network = network)
# Add a track
track = network.get_track("Rob Dougan", "Clubbed To Death (Kurayamino Variation)")
library.add_track(track)
答案 0 :(得分:0)
[发布更新作为答案]
对于有pylast问题的其他人,我将在下面发布一个正确的示例,用于向库中添加曲目。我将错误的网络参数传递给pylast.Library()。
修复上述问题后,代码开始抛出缺少的参数错误。我必须在Library类的add_track()函数中添加以下行到pylast.py(第1970行)。这是Last.fm API的必要参数。
params['artist'] = track.get_artist().get_name()
将曲目添加到用户库的工作示例:
import pylast
# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from http://www.last.fm/api/account for Last.fm
API_KEY = "your_key"
API_SECRET = "your_secret"
# In order to perform a write operation you need to authenticate yourself
username = "username"
password_hash = pylast.md5("password")
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)
# Get the User's library
library = pylast.Library(user = "username", network = network)
# Add a track
track = network.get_track("Rob Dougan", "Clubbed To Death (Kurayamino Variation)")
library.add_track(track)