Last.fm api 无效方法
我正在尝试编写一个 python 脚本来查询 Last.fm,但我不断收到返回的无效方法错误。
我不想链接到预先编写的last.fm python 库,我试图将其作为“测试我所知道的”类型的项目。提前致谢!
import urllib
import httplib
params = urllib.urlencode({'method' : 'artist.getsimilar',
'artist' : 'band',
'limit' : '5',
'api_key' : #API key goes here})
header = {"user-agent" : "myapp/1.0"}
lastfm = httplib.HTTPConnection("ws.audioscrobbler.com")
lastfm.request("POST","/2.0/?",params,header)
response = lastfm.getresponse()
print response.read()
I am trying to write a python script to do a query to Last.fm, but I keep getting an invalid method error returned.
I don't want links to pre-written last.fm python libraries, I am trying to do this as a "test what I know" kind of project. Thanks in advance!
import urllib
import httplib
params = urllib.urlencode({'method' : 'artist.getsimilar',
'artist' : 'band',
'limit' : '5',
'api_key' : #API key goes here})
header = {"user-agent" : "myapp/1.0"}
lastfm = httplib.HTTPConnection("ws.audioscrobbler.com")
lastfm.request("POST","/2.0/?",params,header)
response = lastfm.getresponse()
print response.read()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的请求缺少内容类型:“application/x-www-form-urlencoded”。这有效:
You lack Content-type for your request: "application/x-www-form-urlencoded". This works:
Last.fm Artist.getSimilar API 方法不需要 POST,可以使用 GET 来完成。
只有更改数据的 API 方法才需要 POST 方法。
the Last.fm artist.getSimilar API method does not require POST, it can be done with a GET.
Only API methods that change data require the POST method.