350-401 exam dumps

350-401 practice question 311 of 631

Implementing Cisco Enterprise Network Core Technologies. Professional level, Cisco. Free question with the correct answer and a full explanation.

350-401 Question 311

Single answer

A network engineer has written the following Python script to retrieve the hostname of a Cisco device via NETCONF. However, the script is returning an error. Identify the issue in the code.

from ncclient import manager

with manager.connect(
    host='192.168.1.1',
    port=830,
    username='admin',
    password='password',
    hostkey_verify=False
) as m:
    filter = "<filter><native xmlns='http://cisco.com/ns/yang/Cisco-IOS-XE-native'></native></filter>"
    response = m.get(filter=filter)
    print(response['hostname'])

What is the issue?

  1. A

    The 'hostkey_verify' parameter should be set to 'True' for secure connections.

  2. B

    The 'filter' string is incorrectly formatted and does not match the YANG model.

  3. C

    The 'response' object does not support dictionary-style indexing with square brackets.

  4. D

    The 'port' parameter should be set to 22 instead of 830 for NETCONF.

Show answer and explanation

Correct answer: C

Explanation

The issue lies in the way the 'response' object is being accessed. The 'm.get()' method returns an XML object, not a dictionary, so using square brackets to access 'hostname' is incorrect. To fix this, the engineer should parse the XML response using a library like 'xml.etree.ElementTree' or 'lxml' to extract the hostname.

  • A. Incorrect.

    The 'hostkey_verify' parameter being set to 'False' is acceptable for testing purposes, though it is not recommended for production environments.

  • B. Incorrect.

    The format of the 'filter' string is correct and matches the structure of the YANG model for Cisco IOS XE.

  • C. Correct.

    The 'response' object returned by the 'm.get()' method is an XML object, and it does not support dictionary-style indexing. The correct approach is to parse the XML response to extract the hostname.

  • D. Incorrect.

    Port 830 is the default port for NETCONF, so this is correctly configured in the script.

Timed practice exam

Take a 350-401 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam