Exceptions
CanvasAPI may return a number of different exceptions, which are listed below.
Quick Guide
Exception |
Status Code |
Explanation |
400 |
Canvas was unable to process the request. |
|
401 |
The supplied API key is invalid. |
|
401 |
CanvasAPI’s key is valid, but is unauthorized to access the requested resource. |
|
403 |
Canvas has denied access to the resource for this user. |
|
404 |
Canvas could not locate the requested resource. |
|
409 |
Canvas had a conflict with an existing resource. |
|
422 |
Canvas was unable to process the request. |
|
429 |
Canvas is throttling this request. Try again later. |
|
N/A |
A required keyword argument was not included. |
|
N/A |
An unknown error was thrown. |
Class Reference
- class canvasapi.exceptions.CanvasException(message)
Base class for all errors returned by the Canvas API.
The
CanvasExceptionexception is a basic library exception that all other exceptions inherit from. It is also thrown whenever an error occurs but a more specific exception isn’t available or appropriate.Here’s a simple example of catching a
CanvasException:from canvasapi.exceptions import CanvasException try: canvas.get_course(1) except CanvasException as e: print(e)
- class canvasapi.exceptions.BadRequest(message)
Canvas was unable to understand the request. More information may be needed.
The
BadRequestexception is thrown when Canvas returns an HTTP 400 error.
- class canvasapi.exceptions.InvalidAccessToken(message)
CanvasAPI was unable to make an API connection.
The
InvalidAccessTokenexception is thrown when Canvas returns an HTTP 401 error and includes aWWW-Authenticateheader.This indicates that the supplied API Key is invalid.
- class canvasapi.exceptions.Unauthorized(message)
CanvasAPI’s key is valid, but is unauthorized to access the requested resource.
The
Unauthorizedexception is thrown when Canvas returns an HTTP 401 error and does NOT include aWWW-Authenticateheader.This indicates that the supplied API Key is probably valid, but the calling user does not have permission to access this resource.
- class canvasapi.exceptions.ResourceDoesNotExist(message)
Canvas could not locate the requested resource.
The
ResourceDoesNotExistexception is thrown when Canvas returns an HTTP 404 error.
- class canvasapi.exceptions.RequiredFieldMissing(message)
A required field is missing.
The
RequiredFieldMissingexception is thrown when required fields are not passed to a method’s keyword arguments. This is common in cases where the required field must be represented as a dictionary. See our documentation on keyword arguments for examples of how to use keyword arguments in CanvasAPI.
- class canvasapi.exceptions.Forbidden(message)
Canvas has denied access to the resource for this user.
The
Forbiddenexception is thrown when Canvas returns an HTTP 403 error.
- class canvasapi.exceptions.Conflict(message)
Canvas had a conflict with an existing resource.
The
Conflictexception is thrown when Canvas returns an HTTP 409 error.
- class canvasapi.exceptions.UnprocessableEntity(message)
Canvas was unable to process the entity.
The
UnprocessableEntityexception is thrown when Canvas returns an HTTP 422 error.
- class canvasapi.exceptions.RateLimitExceeded(message)
Canvas has recieved to many requests from this access token and is throttling this request. Try again later.
The
RateLimitExceededexception is thrown when Canvas returns an HTTP 429 error. It will include the value of theX-Rate-Limit-Remainingheader (if available) for reference.