从genius api获取歌词给出错误



所以我正在研究一个不和谐的机器人,将使用lyricsgenius api搜索歌词。然而,当我尝试使用genius.search_lyrics(arg),其中arg是歌词的用户试图找到。它给了我一个错误:requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://genius.com/api/search/lyric?q=rap+god

所以在没有找到任何可以修复它的东西之后,我尝试了一种不同的方式。我首先使用请求来查找歌曲id,在这一点上一切都工作(它获得歌曲id,标题等)。但是,当我试图使用lyricsgenius搜索歌词与歌曲id。song = genius.search_song(title=full_title, artist=artist, song_id=song_id)这行不通。给了我这个错误:requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://genius.com/Eminem-rap-god-lyrics

这是我的代码:

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)

对于任何面临相同错误的人,这里有github问题

,似乎没有解决办法,所以不要使用lyricsgenius api

相关内容

最新更新