我正在尝试编写一个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()发布于 2010-12-06 17:50:12
您的请求缺少内容类型的:"application/x-www-form-urlencoded".这是可行的:
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",
"Content-type": "application/x-www-form-urlencoded"}
lastfm = httplib.HTTPConnection("ws.audioscrobbler.com")
lastfm.request("POST","/2.0/?",params,header)
response = lastfm.getresponse()
print response.read()发布于 2011-01-30 05:44:15
Last.fm artist.getSimilar API方法不需要POST,它可以通过GET完成。
只有更改数据的API方法需要POST方法。
https://stackoverflow.com/questions/4362900
复制相似问题