300-435 exam dumps

300-435 practice question 86 of 322

Automating Cisco Enterprise Solutions. Professional level, Cisco. Free question with the correct answer and a full explanation.

300-435 Question 86

Single answer

You are tasked with configuring a Cisco IOS-XE device using the RESTCONF API. You need to use the Python requests library to send a PATCH request to update the hostname of the device. Which code snippet correctly demonstrates this process?

  1. A

    import requests url = 'https://10.10.20.48/restconf/data/Cisco-IOS-XE-native:native/hostname' headers = {'Content-Type': 'application/yang-data+json'} data = {'Cisco-IOS-XE-native:hostname': 'NewHostname'} response = requests.patch(url, headers=headers, data=data, auth=('admin', 'C1sco12345'))

  2. B

    import requests url = 'https://10.10.20.48/restconf/data/Cisco-IOS-XE-native:native/hostname' headers = {'Content-Type': 'application/yang-data+json'} data = {'Cisco-IOS-XE-native:hostname': 'NewHostname'} response = requests.patch(url, headers=headers, json=data, auth=('admin', 'C1sco12345'))

  3. C

    import requests url = 'https://10.10.20.48/restconf/data/Cisco-IOS-XE-native:native/hostname' headers = {'Accept': 'application/yang-data+json'} data = {'Cisco-IOS-XE-native:hostname': 'NewHostname'} response = requests.get(url, headers=headers, json=data, auth=('admin', 'C1sco12345'))

  4. D

    import requests url = 'https://10.10.20.48/restconf/data/Cisco-IOS-XE-native:native/hostname' headers = {'Content-Type': 'application/json'} data = {'Cisco-IOS-XE-native:hostname': 'NewHostname'} response = requests.put(url, headers=headers, json=data, auth=('admin', 'C1sco12345'))

Show answer and explanation

Correct answer: B

Explanation

To configure a device using RESTCONF and the Python requests library, you must send the correct HTTP request with properly formatted headers and payload. PATCH is the appropriate method for partial updates, and the json parameter ensures the payload is serialized as JSON. The correct headers (Content-Type or Accept) are also necessary for RESTCONF APIs to interpret the request properly.

  • A. Incorrect.

    This option is incorrect because the data parameter is used instead of json, which means the payload will not be properly serialized to JSON. RESTCONF APIs require properly formatted JSON payloads.

  • B. Correct.

    This is the correct option. It uses the json parameter to ensure the payload is serialized to JSON format, includes the correct headers, and uses the PATCH method to update the hostname.

  • C. Incorrect.

    This option is incorrect because the GET method is used instead of PATCH. The GET method is used to retrieve data, not to update it.

  • D. Incorrect.

    This option is incorrect because the PUT method is used instead of PATCH, and the Content-Type header is not specific to YANG data. While PUT can replace the resource, it is not the recommended method for partial resource updates in this scenario.

Timed practice exam

Take a 300-435 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