nerdexam
Cisco

200-901 · Question #215

Refer to the exhibit. A Python code has been written to query a device. The executed code results in the error shown. Which action resolves the problem?

The correct answer is D. import requests. The error occurs because the 'requests' module is referenced in the code but was never imported. In Python, you must explicitly import any module before using it. The fix is to add 'import requests' at the top of the script. Option A ('import json') imports the wrong module and w

Software Development and Design

Question

Refer to the exhibit. A Python code has been written to query a device. The executed code results in the error shown. Which action resolves the problem?

Exhibit

200-901 question #215 exhibit

Options

  • Aimport json
  • Brequests("GET", base_url + request_url, cookles=cookies)
  • Cpip install requests
  • Dimport requests

How the community answered

(30 responses)
  • B
    3% (1)
  • C
    7% (2)
  • D
    90% (27)

Explanation

The error occurs because the 'requests' module is referenced in the code but was never imported. In Python, you must explicitly import any module before using it. The fix is to add 'import requests' at the top of the script. Option A ('import json') imports the wrong module and wouldn't fix the NameError for 'requests'. Option B shows a corrected function call syntax but doesn't resolve the missing import. Option C ('pip install requests') installs the package at the system level - this may be needed if the package is missing, but the immediate cause of the shown error is a missing import statement, not a missing installation (and installing without importing still won't fix the code).

Topics

#Python programming#Module import#HTTP requests#API interaction

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice