wxc_sdk.rest module
REST session for Webex API requests
- class wxc_sdk.rest.SingleError(*, description: str, errorCode: int | None = None)[source]
Bases:
BaseModelRepresentation of single error in the body of an HTTP error response from Webex
- description: str
- error_code: int | None
- property code: int | None
Error code or None
- Returns:
error code
- class wxc_sdk.rest.ErrorDetail(*, errorCode: int | None = None, message: str, errors: list[SingleError] | None = None, trackingId: str, **extra_data: Any)[source]
Bases:
ApiModelRepresentation of error details in the body of an HTTP error response from Webex
- error_code: int | None
- message: str
error message
- errors: list[SingleError] | None
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.rest.RestError(msg: str, response: Response)[source]
Bases:
HTTPErrorA REST error
- request: PreparedRequest
- __init__(msg: str, response: Response)[source]
Initialize RequestException with request and response objects.
- property description: str
error description
- property code: str
error code
- class wxc_sdk.rest.RestSession(*, tokens: Tokens, concurrent_requests: int, retry_429: bool = True, proxy_url: str | None = None, verify: bool | str | None = None)[source]
Bases:
Session- REST session used for API requests:
includes an Authorization header in reach request
implements retries on 429
loads deserializes JSON data if needed
- BASE: ClassVar[str] = 'https://webexapis.com/v1'
base URL for all Webex API requests
- __init__(*, tokens: Tokens, concurrent_requests: int, retry_429: bool = True, proxy_url: str | None = None, verify: bool | str | None = None)[source]
- retry_429: bool
- register_response_callback(callback: Callable[[Response, int], None]) str[source]
Register a response callback
Registered response callbacks are called with the response object and the time the request took for all responses. This can be used for logging or other purposes.
- Parameters:
callback – callback to register
- Returns:
callback ID
- unregister_response_callback(id: str)[source]
Unregister a response callback
- Parameters:
id – callback ID
- property access_token: str
access token used for all requests
- Returns:
access token
- Return type:
str
- rest_get(*args, **kwargs) str | dict[source]
GET request
- Parameters:
args
kwargs
- Returns:
deserialized JSON content or body text
- rest_post(*args, **kwargs) str | dict[source]
POST request
- Parameters:
args
kwargs
- Returns:
deserialized JSON content or body text
- rest_put(*args, **kwargs) str | dict[source]
PUT request
- Parameters:
args
kwargs
- Returns:
deserialized JSON content or body text
- follow_pagination(url: str, model: type[ApiModel] | None = None, params: dict | None = None, item_key: str | None = None, **kwargs) Generator[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
- wxc_sdk.rest.dump_response(response: Response, 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
file (TextIOBase) – stream to dump to
dump_log (logging.Logger) – logger to dump to
diff_ns (int) – time the request took (in ns)