首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Last.fm接口方法无效

Last.fm接口方法无效
EN

Stack Overflow用户
提问于 2010-12-06 11:20:27
回答 2查看 1K关注 0票数 2

我正在尝试编写一个python脚本来查询Last.fm,但是我总是得到一个返回的无效方法错误。

我不想要链接到预先编写的last.fm python库,我正试图这样做,作为一个“测试我所知道的”类型的项目。提前感谢!

代码语言:javascript
复制
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()
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-12-06 17:50:12

您的请求缺少内容类型的"application/x-www-form-urlencoded".这是可行的:

代码语言:javascript
复制
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()
票数 2
EN

Stack Overflow用户

发布于 2011-01-30 05:44:15

Last.fm artist.getSimilar API方法不需要POST,它可以通过GET完成。

只有更改数据的API方法需要POST方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4362900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档