mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-07 23:22:49 +00:00
commit
408a3bbc36
@ -51,7 +51,7 @@ class Spotify(object):
|
|||||||
max_get_retries = 10
|
max_get_retries = 10
|
||||||
|
|
||||||
def __init__(self, auth=None, requests_session=True,
|
def __init__(self, auth=None, requests_session=True,
|
||||||
client_credentials_manager=None, requests_timeout=None):
|
client_credentials_manager=None, proxies=None, requests_timeout=None):
|
||||||
'''
|
'''
|
||||||
Create a Spotify API object.
|
Create a Spotify API object.
|
||||||
|
|
||||||
@ -63,12 +63,15 @@ class Spotify(object):
|
|||||||
for performance reasons (connection pooling).
|
for performance reasons (connection pooling).
|
||||||
:param client_credentials_manager:
|
:param client_credentials_manager:
|
||||||
SpotifyClientCredentials object
|
SpotifyClientCredentials object
|
||||||
|
:param proxies:
|
||||||
|
Definition of proxies (optional)
|
||||||
:param requests_timeout:
|
:param requests_timeout:
|
||||||
Tell Requests to stop waiting for a response after a given number of seconds
|
Tell Requests to stop waiting for a response after a given number of seconds
|
||||||
'''
|
'''
|
||||||
self.prefix = 'https://api.spotify.com/v1/'
|
self.prefix = 'https://api.spotify.com/v1/'
|
||||||
self._auth = auth
|
self._auth = auth
|
||||||
self.client_credentials_manager = client_credentials_manager
|
self.client_credentials_manager = client_credentials_manager
|
||||||
|
self.proxies = proxies
|
||||||
self.requests_timeout = requests_timeout
|
self.requests_timeout = requests_timeout
|
||||||
|
|
||||||
if isinstance(requests_session, requests.Session):
|
if isinstance(requests_session, requests.Session):
|
||||||
@ -102,7 +105,7 @@ class Spotify(object):
|
|||||||
|
|
||||||
if self.trace_out:
|
if self.trace_out:
|
||||||
print(url)
|
print(url)
|
||||||
r = self._session.request(method, url, headers=headers, **args)
|
r = self._session.request(method, url, headers=headers, proxies=self.proxies, **args)
|
||||||
|
|
||||||
if self.trace: # pragma: no cover
|
if self.trace: # pragma: no cover
|
||||||
print()
|
print()
|
||||||
|
@ -23,7 +23,7 @@ class SpotifyOauthError(Exception):
|
|||||||
class SpotifyClientCredentials(object):
|
class SpotifyClientCredentials(object):
|
||||||
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):
|
def __init__(self, client_id=None, client_secret=None, proxies=None):
|
||||||
"""
|
"""
|
||||||
You can either provid a client_id and client_secret to the
|
You can either provid 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
|
||||||
@ -44,6 +44,7 @@ class SpotifyClientCredentials(object):
|
|||||||
self.client_id = client_id
|
self.client_id = client_id
|
||||||
self.client_secret = client_secret
|
self.client_secret = client_secret
|
||||||
self.token_info = None
|
self.token_info = None
|
||||||
|
self.proxies = proxies
|
||||||
|
|
||||||
def get_access_token(self):
|
def get_access_token(self):
|
||||||
"""
|
"""
|
||||||
@ -70,7 +71,7 @@ class SpotifyClientCredentials(object):
|
|||||||
headers = {'Authorization': 'Basic %s' % auth_header}
|
headers = {'Authorization': 'Basic %s' % auth_header}
|
||||||
|
|
||||||
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
||||||
headers=headers, verify=True)
|
headers=headers, verify=True, proxies=self.proxies)
|
||||||
if response.status_code is not 200:
|
if response.status_code is not 200:
|
||||||
raise SpotifyOauthError(response.reason)
|
raise SpotifyOauthError(response.reason)
|
||||||
token_info = response.json()
|
token_info = response.json()
|
||||||
@ -210,7 +211,7 @@ class SpotifyOAuth(object):
|
|||||||
headers = {'Authorization': 'Basic %s' % auth_header}
|
headers = {'Authorization': 'Basic %s' % auth_header}
|
||||||
|
|
||||||
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
||||||
headers=headers, verify=True)
|
headers=headers, verify=True, proxies=self.proxies)
|
||||||
if response.status_code is not 200:
|
if response.status_code is not 200:
|
||||||
raise SpotifyOauthError(response.reason)
|
raise SpotifyOauthError(response.reason)
|
||||||
token_info = response.json()
|
token_info = response.json()
|
||||||
@ -238,7 +239,7 @@ class SpotifyOAuth(object):
|
|||||||
headers = {'Authorization': 'Basic %s' % auth_header}
|
headers = {'Authorization': 'Basic %s' % auth_header}
|
||||||
|
|
||||||
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
||||||
headers=headers)
|
headers=headers, proxies=self.proxies)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
if False: # debugging code
|
if False: # debugging code
|
||||||
print('headers', headers)
|
print('headers', headers)
|
||||||
|
Loading…
Reference in New Issue
Block a user