Errors
Web errors for Authorisation and Client.
Base error for all web status errors. |
|
4xx - Base client error. |
|
5xx - Base server error. |
|
400 - Bad request. |
|
401 - Unauthorised. |
|
403 - Forbidden. |
|
404 - Not found. |
|
429 - Too many requests. |
|
500 - Internal server error. |
|
502 - Bad gateway. |
|
503 - Service unavailable. |
Clients facing the Web API raise errors when recieving bad status codes.
Only errors documented in the Web API documentation are expected and provided.
Other exceptions are raised as ClientError or ServerError.
import tekore as tk
conf = tk.config_from_environment()
token = tk.request_client_token(*conf[:2])
spotify = tk.Spotify(token)
try:
spotify.album('not-a-real-album')
except tk.BadRequest:
print('Whoops, bad request!')
except tk.HTTPError:
print('Something is seriously wrong.')
Error objects also contain the relevant Request and Response
objects for closer inspection.
try:
spotify.album('not-a-real-album')
except tk.BadRequest as ex:
print(str(ex))
print(ex.request)
print(ex.response)
- class tekore.HTTPError(message, request, response)
Bases:
ExceptionBase error for all web status errors.
- request
request that led to the error
- response
response from the web server
- class tekore.BadRequest(message, request, response)
Bases:
ClientError400 - Bad request.
The request could not be understood by the server due to malformed syntax.
- class tekore.Unauthorised(message, request, response)
Bases:
ClientError401 - Unauthorised.
The request requires user authentication or, if the request included authorization credentials, authorization has been refused for those credentials.
The scopes associated with the call are attached to this class.
- optional_scope: str
- required_scope: str
- scope: str
- class tekore.Forbidden(message, request, response)
Bases:
ClientError403 - Forbidden.
The server understood the request, but is refusing to fulfill it.
- class tekore.NotFound(message, request, response)
Bases:
ClientError404 - Not found.
The requested resource could not be found. This error can be due to a temporary or permanent condition.
- class tekore.TooManyRequests(message, request, response)
Bases:
ClientError429 - Too many requests.
Rate limiting has been applied.
- class tekore.InternalServerError(message, request, response)
Bases:
ServerError500 - Internal server error.
You should never receive this error because the clever coders at Spotify catch them all… But if you are unlucky enough to get one, please report it to Spotify through their GitHub (spotify/web-api).
- class tekore.BadGateway(message, request, response)
Bases:
ClientError502 - Bad gateway.
The server was acting as a gateway or proxy and received an invalid response from the upstream server.
Bases:
ClientError503 - Service unavailable.
The server is currently unable to handle the request due to a temporary condition which will be alleviated after some delay. You can choose to resend the request again.