pythonhttprequestgenius-api

Genius API Search result successful but no hits


When making a call to the Genius API (the music lyric service) search capability to search for a specific song by title, my GET request is successfully processed and returns a HTTP status code of 200, but the JSON response returns no hits for the song I searched.

{u'meta': {u'status': 200}, u'response': {u'hits': []}}

Notice the value for the hits key is an empty array. This is strange, since when "testing" the same call on the Genius API Docs site https://docs.genius.com/#web_pages-h2 with the same OAuth2 access token I'm able to get 10 hits for the same search. I've tried searching multiple song titles with the same results.

I'm using Python 2.7.12, and I replaced my API call access token with AccessTOKEN below so I'm not sharing that publicly (though I was testing with the correct access token)

#!/usr/bin/env python
# -*- coding=utf-8 -*-
import requests

baseUrl = "http://api.genius.com"

headers = {'Authorization': 'Bearer AccessTOKEN'}
searchUrl = baseUrl + "/search"
songTitle = "Shelter"
data = {'q': songTitle}
response = requests.get(searchUrl, data=data, headers=headers)
json = response.json()
print json

Any ideas?


Solution

  • The data parameter is used for a POST request. Since this is a GET request, you should pass your data to the params parameter.

    response = requests.get(searchUrl, params=data, headers=headers)