ETExamTower
Q39Software Development and Design

Drag and drop the expressions below onto the code to implement error handling. Not all options are used. <DragDrop items={["if response == 601:","else:","when:","if status == 201:","elif:"]} slots={[{"answer":"if status == 201:","id":"condition"},{"answer":"else:","id":"failure_branch"}]} template={"base_url = “https://api.meraki.com/api/v0”\nposturl = “%s/networks/%s/staticRoutes” % ((str(base_url), str(networkid)))\nheaders = {\n ‘X-cisco-meraki-api-key’: api_key,\n ‘Content-Type’: ‘application/json’\n}\nroutes = [ {\n “subnet”: “10.16.4.0/22”,\n “gatewayIp”: “10.1.0.20”,\n “name”: “ROUTE1”,\n “enabled”: true\n },\n {\n “subnet”: “10.253.254.0/24”,\n “gatewayIp”: “10.1.0.20”,\n “name”: “ROUTE2”,\n “enabled”: true\n },\n {\n “subnet”: “10.168.0.0/21”,\n “gatewayIp”: “10.1.0.20”,\n “name”: “ROUTE3”,\n “enabled”: true\n } ]\n\nfor route in routes:\n print(“Adding static: “ + str(route[’subnet’]))\n response = requests.post(posturl, json=route, headers=headers)\n {{condition}}\n print(“Done!”)\n {{failure_branch}}\n print(“Failed to add static: “ + str(route[’subnet’]) + “\\n” + response.text)"} explanation={"The Meraki static-route creation operation returns HTTP 201 for a successful create operation. The success message therefore belongs under `if status == 201:`, while `else:` reports all unsuccessful responses.\n\n**Learn more:** [Create Network Appliance Static Route — Meraki Dashboard API](https://developer.cisco.com/meraki/api-v1/create-network-appliance-static-route/)"} reuse={false} />

← → navigate · a answer
Discussion · 5
28
I agree with 'if response == 201:' & 'else:'
5
I agree. If response ==201 and else
4
The closest answer is `if status == 201:` & `else:` as everyone already stated. The problem here is the `status` variable is nowhere to be found. This is probably a typo, the correct statement should be `response.status_code == 201`
2
- The body of if runs only if this evaluates to create the route or if the status is equal to 201 if = status == 201 (HTTP 201 is CREATED) = correct - So, if the route is I52not be created, the body of else is executed else: = correct Note: if-else statement evaluates the Boolean expression. If the condition is TRUE then, the code present in the “ if “ block will be executed otherwise the code of the “else“ block will be executed Wrong if response == 601 = there is no 6xx HTTP code elif is used to include multiple conditional (and it is not this case) when is used to run a block of code whenever, during the execution of the program, a condition is met or related to an event (and it is not this case)
1
Right If response 201 Else