ETExamTower
Q44Using APIs

A developer is creating a Python script that uses the Webex REST API to list joined spaces and gracefully handle and print received errors. Drag the code snippets to the matching item numbers to complete the script. <DragDrop items={["401","404","try","except","raise_for_status()"]} slots={[{"answer":"try","id":"item1"},{"answer":"raise_for_status()","id":"item2"},{"answer":"except","id":"item3"},{"answer":"401","id":"item4"},{"answer":"404","id":"item5"}]} template={"import requests\n\nurl = \"https://api.ciscospark.com/v1/rooms\"\nbearer = \"BEARER_TOKEN_HERE\"\nheaders = {\"content-type\": \"application/json\", \"Authorization\": \"Bearer \" + bearer}\n\n{{item1}}:\n response = requests.get(url, headers=headers, verify=False)\n response.{{item2}}\n{{item3}} requests.exceptions.HTTPError as err:\n if response.status_code == {{item4}}:\n print(\"Check Bearer Token\")\n elif response.status_code == {{item5}}:\n print(\"Check API Endpoint uri\")\n elif response.status_code == 500:\n print(\"Server Error, Try again Later\")\n else:\n print(\"HTTP Error\") + str(err)"} explanation={"`try` and `except requests.exceptions.HTTPError` handle HTTP failures raised by `response.raise_for_status()`. HTTP 401 is an authentication failure, so the bearer token should be checked; HTTP 404 indicates a missing or incorrect endpoint/resource URI."} reuse={false} />

Question exhibit
← → navigate · a answer
Discussion · 3
24
Agree with the answer being: 1. try 2. raise_for_status() 3. except 4. 401 5. 404
2
1. try - lets you check a block of code for errors. 2. raise_for_status() - returns an HTTPError object if an error has occurred during the process. 3. except - lets you handle the error. 4. 401 - Is related to Unauthorized (invalid credential or no credentials) 5. 404 - The server can not find the requested resource.
1
Correct answer: 1. try - lets you check a block of code for errors. 2. raise_for_status() - returns an HTTPError object if an error has occurred during the process. 3. except - lets you handle the error. 4. 401 - Is related to Unauthorized (invalid credential or no credentials) 5. 404 - The server can not find the requested resource.