200-901 · Question #5
In python, which expression checks whether the script returns a success status code when the Requests library is used?
The correct answer is B. response.status_code == requests.codes.ok. requests.codes.ok is the correct attribute in the Requests library that resolves to the integer 200 (HTTP OK). Comparing response.status_code == requests.codes.ok is the idiomatic way to verify a successful HTTP response. Option A uses requests.ok, which does not exist as a…
Question
In python, which expression checks whether the script returns a success status code when the Requests library is used?
Options
- Aresponse.status_code == requests.ok
- Bresponse.status_code == requests.codes.ok
- Cresponse.code == requests.codes.ok
- Dresponse.status_code ! == requests.codes.ok
How the community answered
(24 responses)- A8% (2)
- B88% (21)
- D4% (1)
Explanation
requests.codes.ok is the correct attribute in the Requests library that resolves to the integer 200 (HTTP OK). Comparing response.status_code == requests.codes.ok is the idiomatic way to verify a successful HTTP response. Option A uses requests.ok, which does not exist as a module-level attribute (though response.ok is a valid boolean shortcut). Option C uses response.code, which is not a valid attribute on a Requests response object - the correct attribute is response.status_code. Option D uses ! == (with a space), which is a syntax error in Python, and also checks for inequality rather than equality.
Topics
Community Discussion
No community discussion yet for this question.