Utility Classes



exception doapi.ActionError(action)[source]

Bases: exceptions.Exception

New in version 0.2.0.

Raised when raise_for_error() is called on an Action that failed to complete successfully

action = None

The Action that failed


exception doapi.DOAPIError(response)[source]

Bases: exceptions.Exception

An exception raised in reaction to the API endpoint responding with a 4xx or 5xx error. Any method that performs an API request may raise this error.

If the body of the error response is a JSON object, its fields will be added to the DOAPIError’s attributes (except where a pre-existing attribute would be overwritten). DigitalOcean error response bodies have been observed to consist of an object with two string fields, "id" and "message".

Note that this class is only for representing errors reported by the endpoint in response to API requests. Everything else that can go wrong uses the normal Python exceptions.

response = None

The requests.Response object

http_error_msg = None

An error message that should be appropriate for human consumption, containing the type of HTTP error, the URL that was requested, and the body of the response.


exception doapi.WaitTimeoutError(in_progress, attr, value, wait_interval, wait_time)[source]

Bases: exceptions.Exception

New in version 0.2.0.

Raised when the runtime of a wait method exceeds wait_time

in_progress = None

A list of any waited-on objects that have not yet completed

attr = None

The objects’ attribute that was being monitored

value = None

The desired value for the objects’ attr attribute

wait_interval = None

The wait_interval value for the wait operation

wait_time = None

The wait_time value for the wait operation


class doapi.DOEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

Bases: json.encoder.JSONEncoder

A json.JSONEncoder subclass that converts resource objects to dicts for JSONification. It also converts iterators to lists.


Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
        iterable = iter(o)
    except TypeError:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)