ExamGecko
Question list
Search
Search

Question 471 - 200-901 discussion

Report
Export

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

Answers
A.

Option A

B.

Option B

Answers
B.

Option B

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

asked 07/10/2024
MANIVANNAN POOPALASINGHAM
31 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first