mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 17:23:53 +00:00
Add requests_timeout parameter to auth module (#233)
This commit is contained in:
parent
2273696850
commit
1f1e90ed39
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Support `position_ms` optional parameter in `start_playback`
|
- Support `position_ms` optional parameter in `start_playback`
|
||||||
|
- Add `requests_timeout` parameter to authentication methods
|
||||||
|
|
||||||
## [2.8.0] - 2020-02-12
|
## [2.8.0] - 2020-02-12
|
||||||
|
|
||||||
|
|||||||
@ -81,7 +81,7 @@ class SpotifyAuthBase(object):
|
|||||||
class SpotifyClientCredentials(SpotifyAuthBase):
|
class SpotifyClientCredentials(SpotifyAuthBase):
|
||||||
OAUTH_TOKEN_URL = "https://accounts.spotify.com/api/token"
|
OAUTH_TOKEN_URL = "https://accounts.spotify.com/api/token"
|
||||||
|
|
||||||
def __init__(self, client_id=None, client_secret=None, proxies=None):
|
def __init__(self, client_id=None, client_secret=None, proxies=None, requests_timeout=None):
|
||||||
"""
|
"""
|
||||||
You can either provide a client_id and client_secret to the
|
You can either provide a client_id and client_secret to the
|
||||||
constructor or set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET
|
constructor or set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET
|
||||||
@ -92,6 +92,7 @@ class SpotifyClientCredentials(SpotifyAuthBase):
|
|||||||
self.client_secret = client_secret
|
self.client_secret = client_secret
|
||||||
self.token_info = None
|
self.token_info = None
|
||||||
self.proxies = proxies
|
self.proxies = proxies
|
||||||
|
self.requests_timeout = requests_timeout
|
||||||
|
|
||||||
def get_access_token(self, as_dict=True):
|
def get_access_token(self, as_dict=True):
|
||||||
"""
|
"""
|
||||||
@ -137,6 +138,7 @@ class SpotifyClientCredentials(SpotifyAuthBase):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
verify=True,
|
verify=True,
|
||||||
proxies=self.proxies,
|
proxies=self.proxies,
|
||||||
|
timeout=self.requests_timeout,
|
||||||
)
|
)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise SpotifyOauthError(response.reason)
|
raise SpotifyOauthError(response.reason)
|
||||||
@ -173,7 +175,8 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
cache_path=None,
|
cache_path=None,
|
||||||
username=None,
|
username=None,
|
||||||
proxies=None,
|
proxies=None,
|
||||||
show_dialog=False
|
show_dialog=False,
|
||||||
|
requests_timeout=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Creates a SpotifyOAuth object
|
Creates a SpotifyOAuth object
|
||||||
@ -185,6 +188,8 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
- state - security state
|
- state - security state
|
||||||
- scope - the desired scope of the request
|
- scope - the desired scope of the request
|
||||||
- cache_path - path to location to save tokens
|
- cache_path - path to location to save tokens
|
||||||
|
- requests_timeout - tell Requests to stop waiting for a response
|
||||||
|
after a given number of seconds
|
||||||
- username - username of current client
|
- username - username of current client
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -198,6 +203,7 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
)
|
)
|
||||||
self.scope = self._normalize_scope(scope)
|
self.scope = self._normalize_scope(scope)
|
||||||
self.proxies = proxies
|
self.proxies = proxies
|
||||||
|
self.requests_timeout = requests_timeout
|
||||||
self.show_dialog = show_dialog
|
self.show_dialog = show_dialog
|
||||||
|
|
||||||
def get_cached_token(self):
|
def get_cached_token(self):
|
||||||
@ -369,6 +375,7 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
verify=True,
|
verify=True,
|
||||||
proxies=self.proxies,
|
proxies=self.proxies,
|
||||||
|
timeout=self.requests_timeout,
|
||||||
)
|
)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise SpotifyOauthError(response.reason)
|
raise SpotifyOauthError(response.reason)
|
||||||
@ -397,6 +404,7 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
data=payload,
|
data=payload,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
proxies=self.proxies,
|
proxies=self.proxies,
|
||||||
|
timeout=self.requests_timeout,
|
||||||
)
|
)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
if False: # debugging code
|
if False: # debugging code
|
||||||
|
|||||||
@ -66,7 +66,7 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
# >= Python3.2 only
|
# >= Python3.2 only
|
||||||
warnings.filterwarnings(
|
warnings.filterwarnings(
|
||||||
"ignore",
|
"ignore",
|
||||||
category=ResourceWarning, # noqa
|
category=ResourceWarning, # noqa
|
||||||
message="unclosed.*<ssl.SSLSocket.*>")
|
message="unclosed.*<ssl.SSLSocket.*>")
|
||||||
|
|
||||||
missing = list(filter(lambda var: not os.getenv(CCEV[var]), CCEV))
|
missing = list(filter(lambda var: not os.getenv(CCEV[var]), CCEV))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user