0

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
  • 3
  • 2
  • Does [this](https://stackoverflow.com/questions/38489386/python-requests-403-forbidden#38489588) answer your question? – 3nws May 01 '22 at 16:44
  • @3nws I don't think so since there isn't an argument where you can put in the headers. Correct me if I'm wrong tho since I really am not sure! – vixitu May 02 '22 at 09:13
  • maybe you can try another wrapper or implement your own – 3nws May 02 '22 at 09:53

0 Answers0