我需要帮助调试尝试在pylast中使用library.add_track函数时收到的错误。我已经检查过代码,但我不擅长python。我只是试图利用这个包装来添加一个轨道列表到我的图书馆。你可以在这里找到pylast代码:我需要帮助使用python的library.add_track功能(python last.fm api wrapper)
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'
我欣赏的帮助。
UPDATE:
对于其他人具有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)
看起来像'网络= “LastFM等”'你提供'pylast.Library()'可能是错误的说法 - 和应该是某种“网络”对象。尝试将其更改为'network = network'。 – martineau 2011-05-28 16:39:14
只是为了在martin上构建一点,我认为api期望你在library1上创建的网络实例 – Paulo 2011-05-28 16:43:52
谢谢你们,这是我应该看到的一个明显问题。我开始基于别人的示例代码工作。 – Kicker 2011-05-28 17:25:28