ExamGecko
Home Home / Cisco / 200-901

Cisco 200-901 Practice Test - Questions Answers, Page 48

Question list
Search
Search

Refer to the exhibit.

A developer creates a Python script by using the Cisco Meraki API. The solution must:

* Obtain a list of HTTP servers for a network named 'netl'.

* Print the response body if the HTTP status code is 200.

* Handle the timeout requests as exceptions, and print Timeout Error next to the exception to stdout.

Which block of code completes the script?

A)

B)

A.

Option A

A.

Option A

Answers
B.

Option B

B.

Option B

Answers
Suggested answer: A

Explanation:

The block of code that correctly completes the script should handle timeout exceptions and print the error, as well as print the response body if the HTTP status code is 200. Option A achieves this:

import requests

url = 'https://api.meraki.com/api/v0/networks/net1/httpServers'

headers = { 'Accept': 'application/json' }

response = requests.get(url=url, headers=headers, verify=False, timeout=5)

try:

response = requests.get(url, headers=headers, verify=False, timeout=5)

response.raise_for_status()

except requests.Timeout as e:

print('Timeout Error: {}'.format(e))

if response.status_code == 200:

print(response.text)

This code makes a GET request to the specified URL, handles the timeout exception by printing a message, and prints the response body if the status code is 200.

Requests: Handling Timeouts

Python Requests: Response Status Code

Total 471 questions
Go to page: of 48