mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-04 22:32:40 +00:00
Propagate refresh token error #259
https://github.com/plamere/spotipy/issues/259 (before upstream support)
This commit is contained in:
parent
9c9ae86a23
commit
f42801ae90
@ -1,2 +1,3 @@
|
||||
VERSION='2.0.1'
|
||||
from .client import Spotify, SpotifyException
|
||||
from .client import Spotify
|
||||
from .exceptions import SpotifyException
|
@ -9,26 +9,12 @@ import time
|
||||
|
||||
import six
|
||||
|
||||
from exceptions import SpotifyException
|
||||
|
||||
""" A simple and thin Python library for the Spotify Web API
|
||||
"""
|
||||
|
||||
|
||||
class SpotifyException(Exception):
|
||||
def __init__(self, http_status, code, msg, headers=None):
|
||||
self.http_status = http_status
|
||||
self.code = code
|
||||
self.msg = msg
|
||||
# `headers` is used to support `Retry-After` in the event of a
|
||||
# 429 status code.
|
||||
if headers is None:
|
||||
headers = {}
|
||||
self.headers = headers
|
||||
|
||||
def __str__(self):
|
||||
return 'http status: {0}, code:{1} - {2}'.format(
|
||||
self.http_status, self.code, self.msg)
|
||||
|
||||
|
||||
class Spotify(object):
|
||||
"""
|
||||
Example usage::
|
||||
|
16
spotipy/exceptions.py
Normal file
16
spotipy/exceptions.py
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
class SpotifyException(Exception):
|
||||
def __init__(self, http_status, code, msg, headers=None):
|
||||
self.http_status = http_status
|
||||
self.code = code
|
||||
self.msg = msg
|
||||
# `headers` is used to support `Retry-After` in the event of a
|
||||
# 429 status code.
|
||||
if headers is None:
|
||||
headers = {}
|
||||
self.headers = headers
|
||||
|
||||
def __str__(self):
|
||||
return 'http status: {0}, code:{1} - {2}'.format(
|
||||
self.http_status, self.code, self.msg)
|
@ -11,6 +11,8 @@ import sys
|
||||
import six
|
||||
import six.moves.urllib.parse as urllibparse
|
||||
|
||||
from exceptions import SpotifyException
|
||||
|
||||
|
||||
class SpotifyOauthError(Exception):
|
||||
pass
|
||||
@ -236,13 +238,17 @@ class SpotifyOAuth(object):
|
||||
|
||||
response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
|
||||
headers=headers, proxies=self.proxies)
|
||||
if response.status_code != 200:
|
||||
if False: # debugging code
|
||||
print('headers', headers)
|
||||
print('request', response.url)
|
||||
self._warn("couldn't refresh token: code:%d reason:%s" \
|
||||
% (response.status_code, response.reason))
|
||||
return None
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except:
|
||||
message = "Couldn't refresh token: code:%d reason:%s" % (
|
||||
response.status_code,
|
||||
response.reason,
|
||||
)
|
||||
raise SpotifyException(response.status_code,
|
||||
-1,
|
||||
message,
|
||||
headers)
|
||||
token_info = response.json()
|
||||
token_info = self._add_custom_values_to_token_info(token_info)
|
||||
if not 'refresh_token' in token_info:
|
||||
|
Loading…
Reference in New Issue
Block a user