LyricsGenius
LyricsGenius copied to clipboard
Total error [Errno 403] 403 Client Error: Forbidden for url
Describe the bug I get an error every time I make an API request to get a chart
Expected behavior I get error: "Total error [Errno 403] 403 Client Error: Forbidden for url". My API requests are blocked, access is denied and I cannot bypass this block. When I click on the link in the response, I get to the page with protection from cloud flare
To Reproduce
genius = lyricsgenius.Genius(access_token='API_KEY',
timeout=20,
retries=3)
def get_lyrics():
try:
while True:
chart = genius.charts(time_period='all_time', chart_genre='rap', per_page='50', page=page)
print(chart)
Include the error message associated with the bug.
Total error [Errno 403] 403 Client Error: Forbidden for url: https://genius.com/api/songs/chart?time_period=all_time&chart_genre=rap&per_page=50&page=1&text_format=plain
Version info
- Package version lyricsgenius 3.0.1
- OS: linux ubuntu 22.04
Additional context Please help me solve this problem
I have the same error! link packages lyricgenius authenticate: https://lyricsgenius.readthedocs.io/en/master/reference/auth.html#oauth2 Auth OAuth2 You can use this class to authenticate yourself or get URLs to redirect your users to and get them to give your Genius app the premissions you need. To find out more about how to use this class visit the Snippets.
classlyricsgenius.auth.OAuth2(client_id, redirect_uri, client_secret=None, scope=None, state=None, client_only_app=False) Genius OAuth2 authorization flow.
Using this class you can authenticate a user, and get their token.
Parameters client_id (str) β Client ID
redirect_uri (str) β Whitelisted redirect URI.
client_secret (str, optional) β Client secret.
scope (tuple | "all", optional) β Token privileges.
state (str, optional) β Request state.
client_only_app (bool, optional) β True to use the client-only authorization flow, otherwise False.
Raises
AssertionError β If neither client_secret, nor client_only_app is supplied.
Same here, did you manage to workaround this ?
root@sopel:/data-test # ./test-env/bin/python3
Python 3.9.18 (main, Apr 9 2024, 01:10:56)
[Clang 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1 on freebsd14
Type "help", "copyright", "credits" or "license" for more information.
>>> import lyricsgenius
>>> genius.search_lyrics(text)
KeyboardInterrupt
>>> genius = lyricsgenius.Genius('*********************************************')
>>> genius.search_lyrics('salut')
Traceback (most recent call last):
File "/data-test/test-env/lib/python3.9/site-packages/lyricsgenius/api/base.py", line 80, in _make_request
response.raise_for_status()
File "/data-test/test-env/lib/python3.9/site-packages/requests/models.py", line 1021, 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/lyric?q=salut
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data-test/test-env/lib/python3.9/site-packages/lyricsgenius/api/public_methods/search.py", line 125, in search_lyrics
return self.search(search_term, per_page, page, endpoint)
File "/data-test/test-env/lib/python3.9/site-packages/lyricsgenius/api/public_methods/search.py", line 45, in search
return self._make_request(path, params_=params, public_api=True)
File "/data-test/test-env/lib/python3.9/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/lyric?q=salut
This issue has already been discussed extensively and the only solution is explained in another issue of the same origin.