1

So I am working on a discord bot that will search for the lyrics using the lyricsgenius api. However when I try to use genius.search_lyrics(arg) where arg is the lyrics the user is trying to find. It gives me an error: requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://genius.com/api/search/lyric?q=rap+god

So after not finding anything that would fix it I tried it in a different way. I first used requests to find the song id, which upon this point everything works (it gets the song id, title etc.). But however when I try to use lyricsgenius to search for the lyrics with the song id. song = genius.search_song(title=full_title, artist=artist, song_id=song_id) it doesn't work. And gives me this error: requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://genius.com/Eminem-rap-god-lyrics

This is my code:

genius = Genius(token)

TOKEN = 'token'
base_url = "http://api.genius.com"
headers = {'Authorization': 'Bearer ' + TOKEN}
search_url = base_url + "/search"
song_title = arg # the arg is given by the user
params = {'q': song_title}
response = requests.get(search_url, params=params, headers=headers)
json = response.json()

# send the full title of the song
full_title = json['response']['hits'][0]['result']['full_title']
artist = json['response']['hits'][0]['result']['primary_artist']['name']
FullSearchTerm = f"{artist} {song_title}"
print(FullSearchTerm)

# get the song ID
song_id = json['response']['hits'][0]['result']['id']
print(f"song_id is {song_id}")

song = genius.search_song(title=full_title, artist=artist, song_id=song_id)
print(song.lyrics)
vixitu
  • 13
  • 4

1 Answers1

0

for anyone facing the same error, there's a github issue here

and there seems to be no work arounds, so don't use lyricsgenius api

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33077410) – thedemons Nov 05 '22 at 10:02