Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genius.search_song returns 403 Forbidden #288

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lyricsgenius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
__url__ = 'https://github.com/johnwmillr/LyricsGenius'
__description__ = 'A Python wrapper around the Genius API'
__license__ = 'MIT'
__version__ = '3.1.2'
__version__ = '3.2.0'
8 changes: 8 additions & 0 deletions lyricsgenius/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class API(Sender):
sleep_time (:obj:`str`, optional): time to wait between requests.
retries (:obj:`int`, optional): Number of retries in case of timeouts and
errors with a >= 500 response code. By default, requests are only made once.
user_agent (:obj:`str`, optional): User agent for the request header.
proxy (:obj:`dict[str, str]`, optional): Proxy settings.

Attributes:
response_format (:obj:`str`, optional): API response format (dom, plain, html).
Expand All @@ -55,13 +57,17 @@ def __init__(self,
timeout=5,
sleep_time=0.2,
retries=0,
user_agent='',
proxy=None,
):
super().__init__(
access_token=access_token,
response_format=response_format,
timeout=timeout,
sleep_time=sleep_time,
retries=retries,
user_agent=user_agent,
proxy=proxy,
)

def account(self, text_format=None):
Expand Down Expand Up @@ -524,6 +530,7 @@ def __init__(
timeout=5,
sleep_time=0.2,
retries=0,
user_agent='',
**kwargs
):

Expand All @@ -538,5 +545,6 @@ def __init__(
sleep_time=sleep_time,
retries=retries,
public_api_constructor=public_api_constructor,
user_agent=user_agent,
**kwargs
)
8 changes: 7 additions & 1 deletion lyricsgenius/api/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import os
import platform
from json.decoder import JSONDecodeError

import requests
Expand All @@ -21,12 +22,17 @@ def __init__(
sleep_time=0.2,
retries=0,
public_api_constructor=False,
user_agent='',
proxy=None,
):
self._session = requests.Session()
user_agent_root = f'{platform.system()} {platform.release()}; Python {platform.python_version()}'
self._session.headers = {
'application': 'LyricsGenius',
'User-Agent': 'https://github.com/johnwmillr/LyricsGenius'
'User-Agent': f'({user_agent}) ({user_agent_root})' if user_agent else user_agent_root,
}
if proxy:
self._session.proxies = proxy
if access_token is None:
access_token = os.environ.get('GENIUS_ACCESS_TOKEN')

Expand Down
8 changes: 7 additions & 1 deletion lyricsgenius/genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Genius(API, PublicAPI):
excluded terms with user's. Default excluded terms are listed below.
retries (:obj:`int`, optional): Number of retries in case of timeouts and
errors with a >= 500 response code. By default, requests are only made once.
user_agent (:obj:`str`, optional): User agent for the request header.
proxy (:obj:`dict[str, str]`, optional): Proxy settings.

Attributes:
verbose (:obj:`bool`, optional): Turn printed messages on or off.
Expand Down Expand Up @@ -71,14 +73,18 @@ def __init__(self, access_token=None,
skip_non_songs=True, excluded_terms=None,
replace_default_terms=False,
retries=0,
user_agent='',
proxy=None,
):
# Genius Client Constructor
super().__init__(
access_token=access_token,
response_format=response_format,
timeout=timeout,
sleep_time=sleep_time,
retries=retries
retries=retries,
user_agent=user_agent,
proxy=proxy,
)

self.verbose = verbose
Expand Down
Loading