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)