nerdexam
Cisco

200-901 · Question #679

Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing in the Python script to list all devices. Not all options are used. Answer: Exam Questions, Study…

The correct answer is get; true; exists; content. This question tests the ability to complete a Python script that interacts with a REST API using the 'requests' library to retrieve and parse JSON data.

Cisco Platforms and Development

Question

Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing in the Python script to list all devices. Not all options are used. Answer:

Exam Questions, Study Guides, Practice Tests. Lead the way to help you pass any IT Certification exams, 100% Pass Guaranteed or Full Refund. Especially Cisco, Microsoft, CompTIA, Citrix, EMC, HP, Oracle, VMware, Juniper, Check Point, LPI, Nortel, EXIN and so on. Our Slogan: First Test, First Pass. Help you to pass any IT Certification exams at the first try. You can reach us at any of the email addresses listed below. Any problems about IT certification or our products, you could rely upon us, we will give you satisfactory answers in 24 hours.

Exhibit

200-901 question #679 exhibit

Answer Area

Drag items

okgetrequesttrueexistsyescontent

Correct arrangement

  • get
  • true
  • exists
  • content

Explanation

This question tests the ability to complete a Python script that interacts with a REST API using the 'requests' library to retrieve and parse JSON data.

Approach. The goal is to correctly complete the Python script to list all devices by making an HTTP GET request, handling authentication, verifying SSL, checking for success, and parsing the JSON response. Here's the correct placement for each blank:

  1. Blank 1 (requests.____): The script needs to make an HTTP GET request. The 'requests' library provides the get() method for this purpose.

    • Drag get here: deviceStatsJson = requests.get(str(viptela_url) + ...
  2. Blank 2 (verify=____): The verify parameter in requests controls SSL certificate verification and expects a boolean value. To enable verification, True (or true in a context where Python's boolean is expected) is used.

    • Drag true here: ..., auth=(viptela_user, viptela_pass), verify=true)
  3. Blank 3 (if deviceStatsJson.____): After making a request, it's good practice to check if the request was successful. The requests.Response object has an ok attribute, which is True for successful (2xx) status codes and False otherwise.

    • Drag ok here: if (deviceStatsJson.ok):
  4. Blank 4 (json.loads(deviceStatsJson.____)): To parse the JSON response body, json.loads() expects a string or bytes containing the JSON data. The requests.Response object has a content attribute that returns the response body as bytes (and text for string). Given the available options, content is the correct choice to retrieve the raw response body for parsing.

    • Drag content here: jData = json.loads(deviceStatsJson.content)

Common mistakes.

  • common_mistake. Common mistakes include:
  • Dragging request for Blank 1: While requests.request is a generic method, requests.get is the specific and most common method for HTTP GET requests, making get more appropriate here.
  • Dragging content or exists for Blank 2 (verify=____): The verify parameter expects a boolean. content refers to the response body, and exists is not a valid boolean or keyword for this parameter.
  • Dragging true for Blank 3 (if deviceStatsJson.____): true is a boolean value itself, not an attribute of the Response object that indicates success. The correct attribute is ok (e.g., response.ok).
  • Dragging exists for Blank 4 (json.loads(deviceStatsJson.____)): exists is not an attribute of the requests.Response object that provides the response body. The body is accessed via attributes like text or content.

Concept tested. The core technical concepts tested are Python programming fundamentals, specifically interacting with REST APIs using the 'requests' library, handling HTTP methods (GET), basic authentication, SSL certificate verification, checking HTTP response status codes, and parsing JSON data from an API response.

Topics

#Python Scripting#Network Automation#Cisco APIs#Device Inventory

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice