Preparing Practice Exam…
Please wait a moment while the system generates the exam questions, answers, and study session.
Please wait a moment while the system generates the exam questions, answers, and study session.
Cisco Certified DevNet Associate (DEVASC) · Cisco
Select one answer.
Written by other learners. Comments can disagree with the marked answer — check the official documentation when in doubt.
import requests url = 'https://en.wikipedia.org/api/rest_v1/page/title/Cisco_Systems' s = requests.Session() def get_json(session=None, url="https:example.com"): try: if not session or type(session) is not requests.sessions.Session: raise Exception("Invalid session type") r = session.get(url) if r.status_code < 200 or r.status_code > 307: raise Exception("Status Code not within 2xx and 3xx") return r.json() except requests.exceptions.RequestException as e: raise e("Request failed") finally: session.close() if __name__ == "__main__": items = get_json(session=s,url=url) print(items.get('items')[0].get('page_id')) B throws error, A is the correct answer
B is correct because the .get()
B is missing the [0] to access the first element in the list.