QuestionQ260

Understanding and Using APIs

Question Image

Refer to the exhibit. A developer created a Python script using the Cisco Meraki API. The solution must:

  • Obtain a list of HTTP servers for a network named “net1”.
  • Print the response body when the HTTP status code is 200.
  • Handle timeout requests as exceptions and print Timeout Error next to the exception to stdout.

Which code block completes the script?

  • A
  • B
  • C
  • D
Explanation

Requests raises a Timeout exception for timed-out requests, and requests.Timeout catches it. Binding that exception as e permits printing Timeout Error together with the exception details. Checking response.status_code == 200 and printing response.text outputs the response body only for a successful HTTP 200 response.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!