exam questions

Exam 350-401 All Questions

View all questions & answers for the 350-401 exam

Exam 350-401 topic 1 question 436 discussion

Actual exam question from Cisco's 350-401
Question #: 436
Topic #: 1
[All 350-401 Questions]

Which Python code snippet must be added to the script to save the returned configuration as a JSON-formatted file?

A.

B.

C.

D.

Show Suggested Answer Hide Answer
Suggested Answer: A

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Faridtnx
Highly Voted 2 years, 3 months ago
I've read the for ENCOR we just need to "6.1 Interpret basic Python components and scripts". I wonder why I see alot of high level question about Python here
upvoted 36 times
Solaaa
2 years, 2 months ago
I am wondering as well
upvoted 6 times
...
[Removed]
1 year, 10 months ago
It is really bothering me how many questions there are about programing languages.
upvoted 14 times
mgiuseppe86
1 year, 7 months ago
Im a bit nervous about this stuff. If these are brain dumps from the actual exam, why is this stuff on here? This is not networking. ENCOR is very misleading.
upvoted 3 times
EAC84
1 year ago
even the Cisco U course does not teach this level of detail. The course and the exam is a bit of a scam
upvoted 4 times
...
...
...
PureInertiaCopy
1 year, 8 months ago
Same here...
upvoted 3 times
...
...
attiko
Highly Voted 2 years, 6 months ago
Answer is C, I verified by writing the below program to test: import json import requests url = "http://ip.jsontest.com" response = requests.get(url) print(response) with open("ifaces.json","w") as outfile: outfile.write(response.text)
upvoted 17 times
Zizu007
2 years, 5 months ago
A: wrong - python error: "argument must be str, not dict" B: wrong - python error: "argument must be str, not Response" C: Correct. file created as .json D: Wrong - python error: "argument must be str, not dict"
upvoted 7 times
Colmenarez
1 year, 9 months ago
A is correct. json.loads() is taken response.text
upvoted 1 times
...
...
...
[Removed]
Most Recent 11 months ago
It´s C The ( Response ) object obtained from the ( requests.get() ) method contains the JSON-formatted configuration data in its ( text attribute ).
upvoted 2 times
[Removed]
10 months ago
.........................
upvoted 1 times
...
...
tafisto
1 year ago
can someone show me step-by-step how does this works it always confuses me.do we use postman to do this?.
upvoted 3 times
...
Claudiu1
1 year, 2 months ago
requests.get() returns a "response" object. write() method accepts only string datatypes as arguments, not anything else. A: Wrong: json.loads() method takes a "string" formatted as Json as argument, and returns a dict. Trying to write a 'dict' to a file raises an exception. B: Wrong: Trying to write the whole Response object to a file raises an exception C: Correct: 'text' is an attribute of 'response' which is the response's body as a Json-formatted string. Thus, it can be directly written to the file. D: Wrong: .json() method returns the response's json body to a dictionary, same as json.loads(response.text) does.
upvoted 2 times
...
PureInertiaCopy
1 year, 8 months ago
The correct answer is C. C. with open("ifaces.json", "w") as OutFile: OutFile.write(Response.text) Explanation: When you make a request using the requests.get() method, the response object Response contains the server's response in text format. To save this response as a JSON-formatted file, you need to write the text attribute of the response to the file. Option C does this correctly by using OutFile.write(Response.text). Options A and D are incorrect because they attempt to convert the response content to JSON using json.loads() or Response.json(), respectively. However, in this case, the response is already in text format and should be directly written to the file. Option B is incorrect because it attempts to write the entire response object (Response) to the file, which will not be in valid JSON format.
upvoted 3 times
...
Dannyboy7
1 year, 10 months ago
Answer is C
upvoted 1 times
...
msstanick
1 year, 10 months ago
Ok, I think I got it -> C. Explanation as below. A wrong: json.loads() is used to make a python dictionary out of a json string - this is not what we are looking for as we actually should get a json string. B wrong: This will provide the http response, not a text string. E.g. <Response [200]> if all good. C correct: Since APIs return JSON strings by default we only need to write them into a file. Script example: url = "http://ip.jsontest.com" response = requests.get(url=url) print(response.text," ",type(response.text)) Result: {"ip": "77.112.51.84"} <class 'str'> D wrong: outfile.write(response.json()) changes the type of the data from string to dictionary so we're getting an error: TypeError: write() argument must be str, not dict
upvoted 2 times
...
dnjJ56
2 years, 4 months ago
C Is correct. Tested all answers.
upvoted 3 times
...
Huntkey
2 years, 5 months ago
Should be C. If you just write "response", I believe you will get the "200"
upvoted 2 times
...
Zikosheka
2 years, 6 months ago
I will go with B
upvoted 2 times
...
zeta99
2 years, 6 months ago
B is correct. Response is a variable not a file
upvoted 4 times
...
Wooker
2 years, 7 months ago
B is correct. https://stackabuse.com/reading-and-writing-json-to-a-file-in-python/
upvoted 2 times
Wooker
2 years, 7 months ago
sorry, C is correct.
upvoted 2 times
...
...
Titini
2 years, 7 months ago
D is correct
upvoted 2 times
ImFran
2 years, 4 months ago
This reference is the key https://requests.readthedocs.io/en/latest/user/quickstart/#json-response-content
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago