nerdexam
Cisco

350-901 · Question #25

A developer is creating a Python script to use the Webex Teams REST API to list joined spaces, and gracefully handle and print the errors it receives. Drag and drop the code snippets from the left…

This question tests the ability to construct a Python script using the requests library to authenticate with the Webex Teams REST API, retrieve a list of joined spaces, and gracefully handle HTTP and connection errors.

Using APIs

Question

A developer is creating a Python script to use the Webex Teams REST API to list joined spaces, and gracefully handle and print the errors it receives. Drag and drop the code snippets from the left onto the item numbers on the right that match the missing sections in the exhibit to complete the script.

Explanation

This question tests the ability to construct a Python script using the requests library to authenticate with the Webex Teams REST API, retrieve a list of joined spaces, and gracefully handle HTTP and connection errors.

Approach. The correct approach involves four key sections: (1) setting the Authorization header with a Bearer token (e.g., 'Authorization': 'Bearer <token>'), (2) making a GET request to the Webex rooms endpoint (https://webexapis.com/v1/rooms), (3) calling response.raise_for_status() inside a try block to automatically raise an exception on 4xx/5xx HTTP responses, and (4) catching requests.exceptions.HTTPError (or the broader requests.exceptions.RequestException) in an except block and printing the error. This pattern-Bearer auth, raise_for_status, and exception handling-is the standard Cisco DevNet pattern for graceful Webex API error handling.

Concept tested. Webex Teams REST API authentication (Bearer token), Python requests library usage (GET request, headers), HTTP error handling with raise_for_status() and requests.exceptions.HTTPError, and JSON response parsing.

Reference. Cisco DevNet DEVASC 200-901 - 'Construct a Python script that calls a REST API using the requests library'; Webex REST API docs - GET /v1/rooms endpoint.

Topics

#Python scripting#REST API#Webex Teams API#Error handling

Community Discussion

No community discussion yet for this question.

Full 350-901 Practice