wxc_sdk.rest module
REST session for Webex API requests
- class wxc_sdk.rest.SingleError(*, 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][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.
- description: str
- error_code: int | None
- property code: int | None
Error code or None
- Returns:
error code
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'description': FieldInfo(annotation=str, required=True), 'error_code': FieldInfo(annotation=Union[int, NoneType], required=False, alias='errorCode', alias_priority=2)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class wxc_sdk.rest.ErrorDetail(*, errorCode: int | None = None, message: str, errors: list[SingleError] | None = None, 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][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.
- 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
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'populate_by_name': True, 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'error_code': FieldInfo(annotation=Union[int, NoneType], required=False, alias='errorCode', alias_priority=2), 'errors': FieldInfo(annotation=Union[list[SingleError], NoneType], required=False, alias='errors', alias_priority=1), 'message': FieldInfo(annotation=str, required=True, alias='message', alias_priority=1), 'tracking_id': FieldInfo(annotation=str, required=True, alias='trackingId', alias_priority=1)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- exception wxc_sdk.rest.RestError(msg: str, response: Response)[source]
Bases:
HTTPError
A REST error
Initialize RequestException with request and response objects.
- request: PreparedRequest
- response: Response
- property description: str
error description
- property code: str
error code
- class wxc_sdk.rest.RestSession(*, tokens: Tokens, concurrent_requests: int, retry_429: bool = True)[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 = '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
- 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)