Response

class py42.response.Py42Response(requests_response)

Bases: object

property encoding

The encoding used to decode the response text.

property headers

A case-insensitive dictionary of response headers.

iter_content(chunk_size=1, decode_unicode=False)

Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses.

Parameters
  • chunk_size (int, optional) – The number of bytes it should read into memory. A value of None will function differently depending on the value of stream. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. This is not necessarily the length of each item. Defaults to 1.

  • decode_unicode (bool, optional) – If True, content will be decoded using the best available encoding based on the response. Defaults to False.

property raw_text

The response.Response.text property. It contains raw metadata that is not included in the Py42Response.text property.

property status_code

An integer code of the response HTTP Status, e.g. 404 or 200.

property text

The more useful parts of the HTTP response dumped into a dictionary.

property url

The final URL location of response.

Exceptions

exception py42.exceptions.Py42ArchiveFileNotFoundError(device_guid, file_path)

Bases: py42.exceptions.Py42Error

An exception raised when a resource file is not found or the path is invalid.

exception py42.exceptions.Py42BadRequestError(exception)

Bases: py42.exceptions.Py42HTTPError

A wrapper to represent an HTTP 400 error.

exception py42.exceptions.Py42Error

Bases: Exception

A generic, Py42 custom base exception.

exception py42.exceptions.Py42FeatureUnavailableError

Bases: py42.exceptions.Py42Error

An exception raised when a requested feature is not supported in your Code42 instance.

exception py42.exceptions.Py42ForbiddenError(exception)

Bases: py42.exceptions.Py42HTTPError

A wrapper to represent an HTTP 403 error.

exception py42.exceptions.Py42HTTPError(http_response)

Bases: py42.exceptions.Py42Error

A base custom class to manage all HTTP errors raised by an API endpoint.

property response

The response containing the HTTP error.

exception py42.exceptions.Py42InternalServerError(exception)

Bases: py42.exceptions.Py42HTTPError

A wrapper to represent an HTTP 500 error.

exception py42.exceptions.Py42NotFoundError(exception)

Bases: py42.exceptions.Py42HTTPError

A wrapper to represent an HTTP 404 error.

exception py42.exceptions.Py42SecurityPlanConnectionError(error_message)

Bases: py42.exceptions.Py42Error

An exception raised when the user is not authorized to access the requested resource.

exception py42.exceptions.Py42SessionInitializationError(exception)

Bases: py42.exceptions.Py42Error

An exception raised when a user session is invalid. A session might be invalid due to session timeout, invalid token, etc.

exception py42.exceptions.Py42StorageSessionInitializationError(error_message)

Bases: py42.exceptions.Py42Error

An exception raised when the user is not authorized to initialize a storage session. This may occur when trying to restore a file or trying to get legacy security events.

exception py42.exceptions.Py42UnauthorizedError(exception)

Bases: py42.exceptions.Py42HTTPError

A wrapper to represent an HTTP 401 error.

py42.exceptions.raise_py42_error(raised_error)

Raises the appropriate py42.exceptions.Py42HttpError based on the given error’s response status code.