我需要幫助調試嘗試在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