Repository navigation
|
Lib should use Expected behavior To Reproduce >>> from lyricsgenius import Genius
>>> genius = Genius(TOKEN)
>>> genius.search_song("Hello", "Adele")
Searching for "Hello" by Adele...
Traceback (most recent call last):
File "/root/testvenv/lib/python3.6/site-packages/lyricsgenius/api/base.py", line 80, in _make_request
response.raise_for_status()
File "/root/testvenv/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://genius.com/api/search/multi?q=Hello+Adele
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/testvenv/lib/python3.6/site-packages/lyricsgenius/genius.py", line 401, in search_song
search_response = self.search_all(search_term)
File "/root/testvenv/lib/python3.6/site-packages/lyricsgenius/api/public_methods/search.py", line 210, in search_all
return self.search(search_term, per_page, page, endpoint)
File "/root/testvenv/lib/python3.6/site-packages/lyricsgenius/api/public_methods/search.py", line 45, in search
return self._make_request(path, params_=params, public_api=True)
File "/root/testvenv/lib/python3.6/site-packages/lyricsgenius/api/base.py", line 88, in _make_request
raise HTTPError(response.status_code, error)
requests.exceptions.HTTPError: [Errno 403] 403 Client Error: Forbidden for url: https://genius.com/api/search/multi?q=Hello+AdeleVersion info
Additional context |
Replies: 5 comments 3 replies
|
genius.search_all
genius.song
genius.lyricsBut as you have experienced, VPS and proxy users are very likely to get a 403 error because of Genius's captcha service. Even If we switched to using You can view the list of developers' API methods in the docs. |
|
@allerter I didn't thought about this. That's sad. Btw, thanks for explanation! |
|
fwiw, it seems the authenticated APIs behind api.genius.com work fine behind the VPS, it's just the public ones without auth that run into the 403 issue. There is an authenticated version of the Search API with a similar response format that the library could probably be refactored to, however the auth API is also missing other APIs like /albums so this is an incomplete solution overall. |
|
I have the same error!!! I used the liyricsgenius package. But I don't know how to integrate Genius authentication method into Code. If anyone knows, please help!!! |
I wrote a transparent Cloudflare Worker Proxy to pipe requests through Cloudflare's networkWhich is another way to bypass 403 error if you can't afford an actual proxy. How to set it?
Exampleimport lyricsgenius
from lyricsgenius.api.base import Sender
# --- CONFIGURATION ---
WORKER_URL = "https://lyricsgenius-proxy.your-subdomain.workers.dev"
Sender.API_ROOT = f"{WORKER_URL}/root/"
Sender.PUBLIC_API_ROOT = f"{WORKER_URL}/public/"
Sender.WEB_ROOT = f"{WORKER_URL}/web/"
# --- REST OF THE CODE ---
genius = lyricsgenius.Genius("GENIUS_ACCESS_TOKEN")
song = genius.search_songs("Killer Eminem", 10)
lyrics = genius.search_song(song_id=song['hits'][0]['result']['id'])
print(lyrics.lyrics)Check the repository for more details. |

Genius.search_songis a convenience method and calls the following methods:But as you have experienced, VPS and proxy users are very likely to get a 403 error because of Genius's captcha service. Even If we switched to using
api.genius.com/search, you would still get a 403 error ingenius.lyrics.I suggest either going behind a proxy that works for Genius or limiting your calls to developers' API methods. For example, if you wanted to search for a song and get its info, you could try this which only uses developers' API methods: