Last.fm api invalid method
Question: 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()
    


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

