wxc_sdk.as_rest module

REST session for Webex API requests

class wxc_sdk.as_rest.AsSingleError(*, description: str, errorCode: int = None)[source]

Bases: BaseModel

Representation of single error in the body of an HTTP error response from Webex

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

description: str
error_code: Optional[int]
property code: Optional[int]

Error code or None

Returns

error code

class wxc_sdk.as_rest.AsErrorDetail(*, errorCode: int = None, message: str, errors: list[wxc_sdk.as_rest.AsSingleError], trackingId: str)[source]

Bases: ApiModel

Representation of error details in the body of an HTTP error response from Webex

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

error_code: Optional[int]
message: str

error message

errors: list[wxc_sdk.as_rest.AsSingleError]

list of errors; typically has a single entry

tracking_id: str

tracking ID of the request

property description: str

error description

property code: Optional[int]

error code

exception wxc_sdk.as_rest.AsRestError(request_info: RequestInfo, history: Tuple[ClientResponse, ...], *, code: Optional[int] = None, status: Optional[int] = None, message: str = '', headers: Optional[Union[Mapping[Union[str, istr], str], CIMultiDict, CIMultiDictProxy]] = None)[source]

Bases: ClientResponseError

A REST error

wxc_sdk.as_rest.as_dump_response(*, response: ClientResponse, response_data=None, data=None, json=None, file: Optional[TextIOBase] = None, dump_log: Optional[Logger] = None, diff_ns: Optional[int] = None)[source]

Dump response object to log file

Parameters
  • response – HTTP request response

  • response_data

  • data

  • json

  • file (TextIOBase) – stream to dump to

  • dump_log (logging.Logger) – logger to dump to

  • diff_ns (int) – time the request took (in ns)

class wxc_sdk.as_rest.AsRestSession(*, tokens: Tokens, concurrent_requests: int)[source]

Bases: ClientSession

REST session used for API requests:
  • includes an Authorization header in reach request

  • implements retries on 429

  • loads deserializes JSON data if needed

BASE = 'https://webexapis.com/v1'

base URL for all Webex API requests

property access_token: str

access token used for all requests

Returns

access token

Return type

str

async rest_get(*args, **kwargs) Union[str, dict][source]

GET request

Parameters
  • args

  • kwargs

Returns

deserialized JSON content or body text

async rest_post(*args, **kwargs) Union[str, dict][source]

POST request

Parameters
  • args

  • kwargs

Returns

deserialized JSON content or body text

async rest_put(*args, **kwargs) Union[str, dict][source]

PUT request

Parameters
  • args

  • kwargs

Returns

deserialized JSON content or body text

async rest_delete(*args, **kwargs) None[source]

DELETE request

Parameters
  • args

  • kwargs

async rest_patch(*args, **kwargs) Union[str, dict][source]

PATCH request

Parameters
  • args

  • kwargs

async follow_pagination(url: str, model: Optional[Type[ApiModel]] = None, params: Optional[dict] = None, item_key: Optional[str] = None, **kwargs) AsyncGenerator[ApiModel, None, None][source]

Handling RFC5988 pagination of list requests. Generator of parsed objects

Parameters
  • url (str) – start url for 1st GET

  • model (ApiModel) – data type to return

  • params (Optional[dict]) – URL parameters, optional

  • item_key (str) – key to list of values

Returns

yields parsed objects