Responses#

Unless noted otherwise, all method return values for Globus SDK Clients are GlobusHTTPResponse objects.

To customize client methods with additional detail, the SDK uses subclasses of GlobusHTTPResponse.

class globus_sdk.response.GlobusHTTPResponse(response, client=None)[source]#

Bases: object

Response object that wraps an HTTP response from the underlying HTTP library. If the response is JSON, the parsed data will be available in data, otherwise data will be None and text should be used instead.

The most common response data is a JSON dictionary. To make handling this type of response as seamless as possible, the GlobusHTTPResponse object implements the immutable mapping protocol for dict-style access. This is just an alias for access to the underlying data.

If the response data is not a dictionary or list, item access will raise TypeError.

>>> print("Response ID": r["id"]) # alias for r.data["id"]
Variables:

client – The client instance which made the request

property binary_content: bytes#

The raw response data in bytes.

get(key, default=None)[source]#

get is just an alias for data.get(key, default), but with the added checks that if data is None or a list, it returns the default.

Parameters:
  • key (str) – The string key to lookup in the response if it is a dict

  • default (Any) – The default value to be used if the data is null or a list

Return type:

Any

property headers: Mapping[str, str]#

The HTTP response headers as a case-insensitive mapping.

For example, headers["Content-Length"] and headers["content-length"] are treated as equivalent.

property http_reason: str#

The HTTP reason string from the response.

This is the part of the status line after the status code, and typically is a string description of the status. If the status line is HTTP/1.1 200 OK, then this is the string "OK".

property http_status: int#

The HTTP response status, as an integer.

property text: str#

The raw response data as a string.

class globus_sdk.response.IterableResponse(response, client=None, *, iter_key=None)[source]#

Bases: GlobusHTTPResponse

This response class adds an __iter__ method on an ‘iter_key’ variable. The assumption is that iter produces dicts or dict-like mappings.

class globus_sdk.response.ArrayResponse(response, client=None)[source]#

Bases: GlobusHTTPResponse

This response class adds an __iter__ method which assumes that the top-level data of the response is a JSON array.