Last.fm api invalid method

你。 提交于 2019-12-06 05:23:55
Wojtek

You lack Content-type for your request: "application/x-www-form-urlencoded". This works:

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()

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!