Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def is_token_valid(token):
try:
spotify_client = spotipy.Spotify(auth=token)
spotify_client.current_user()
except spotipy.client.SpotifyException:
return False
return True
print(url)
r = self._session.request(method, url, headers=headers, proxies=self.proxies, **args)
if self.trace: # pragma: no cover
print()
print ('headers', headers)
print ('http status', r.status_code)
print(method, r.url)
if payload:
print("DATA", json.dumps(payload))
try:
r.raise_for_status()
except:
if r.text and len(r.text) > 0 and r.text != 'null':
raise SpotifyException(r.status_code,
-1, '%s:\n %s' % (r.url, r.json()['error']['message']),
headers=r.headers)
else:
raise SpotifyException(r.status_code,
-1, '%s:\n %s' % (r.url, 'error'), headers=r.headers)
finally:
r.connection.close()
if r.text and len(r.text) > 0 and r.text != 'null':
results = r.json()
if self.trace: # pragma: no cover
print('RESP', results)
print()
return results
else:
return None
def _get(self, url, args=None, payload=None, **kwargs):
if args:
kwargs.update(args)
retries = self.max_get_retries
delay = 1
while retries > 0:
try:
return self._internal_call('GET', url, payload, kwargs)
except SpotifyException as e:
retries -= 1
status = e.http_status
# 429 means we hit a rate limit, backoff
if status == 429 or (status >= 500 and status < 600):
if retries < 0:
raise
else:
print ('retrying ...' + str(delay) + 'secs')
time.sleep(delay)
delay += 1
else:
raise
except Exception as e:
raise
print ('exception', str(e))
# some other exception. Requests have
raise ValueError("Must specify type/title/username in `args` \
with init, or in method arguments.")
if not self.type:
self.type = type
if type == "album":
search = title
if "artist" in self.args:
search += " " + self.args["artist"]
list_of_lists = self.spotify.search(q=search, type="album")
list_of_lists = list_of_lists["albums"]["items"]
elif type == "playlist":
try:
list_of_lists = self.spotify.user_playlists(username)["items"]
except spotipy.client.SpotifyException:
print("No user was found by that name.")
return False
if len(list_of_lists) > 0:
the_list = None
for list_ in list_of_lists:
if Config.parse_exact(self) == True:
if list_["name"].encode("utf-8") == title.encode("utf-8"):
if Config.parse_artist(self):
if list_["artists"][0]["name"].encode("utf-8") == \
Config.parse_artist(self).encode('utf-8'):
the_list = self.spotify.album(list_["uri"])
break
else:
if type == "album":
the_list = self.spotify.album(list_["uri"])