wxc_sdk.as_rest module¶
REST session for Webex API requests
- class wxc_sdk.as_rest.AsSingleError(*, description: str, errorCode: int | None = 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: int | None¶
- property code: int | None¶
Error code or None
- Returns:
error code
- class wxc_sdk.as_rest.AsErrorDetail(*, errorCode: int | None = 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: int | None¶
- 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: int | None¶
error code
- exception wxc_sdk.as_rest.AsRestError(request_info: RequestInfo, history: Tuple[ClientResponse, ...], *, code: int | None = None, status: int | None = None, message: str = '', headers: Mapping[str | istr, str] | CIMultiDict | CIMultiDictProxy | None = None)[source]¶
Bases:
ClientResponseError
A REST error
- wxc_sdk.as_rest.as_dump_response(*, response: ClientResponse, response_data=None, data=None, json=None, file: TextIOBase | None = None, dump_log: Logger | None = None, diff_ns: int | None = 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) str | dict [source]¶
GET request
- Parameters:
args –
kwargs –
- Returns:
deserialized JSON content or body text
- async rest_post(*args, **kwargs) str | dict [source]¶
POST request
- Parameters:
args –
kwargs –
- Returns:
deserialized JSON content or body text
- async rest_put(*args, **kwargs) str | dict [source]¶
PUT request
- Parameters:
args –
kwargs –
- Returns:
deserialized JSON content or body text
- async follow_pagination(url: str, model: Type[ApiModel] | None = None, params: dict | None = None, item_key: str | None = 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