Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

Lab - Integrate a REST API in a Python Application

Objectives
Part 1: Launch the DEVASC VM
Part 2: Demonstrate the MapQuest Directions Application
Part 3: Get a MapQuest API Key
Part 4: Build the Basic MapQuest Direction Application
Part 5: Upgrade the MapQuest Directions Application with More Features
Part 6: Test Full Application Functionality

Background / Scenario
In this lab, you will create an application in Visual Studio Code (VS Code) that retrieves JSON data from the
MapQuest Directions API, parses the data, and formats it for output to the user. You will use the GET Route
request from the MapQuest Directions API. Review the GET Route Directions API documentation here:
https://developer.mapquest.com/documentation/directions-api/route/get/
Note: If the above link no longer works, search for “MapQuest API Documentation”.

Required Resources
 1 PC with operating system of your choice
 Virtual Box or VMWare
 DEVASC Virtual Machine

Instructions

Part 1: Launch the DEVASC VM


If you have not already completed the Lab - Install the Virtual Machine Lab Environment, do so now. If you
have already completed that lab, launch the DEVASC VM now.

Part 2: Demonstrate the MapQuest Directions Application


Your instructor may demonstrate the MapQuest Directions Application and show you the script used to create
it. However, you will create this script step by step in this lab.
The application asks for a starting location and a destination. It then requests JSON data from the MapQuest
Directions API, parses it, and displays useful information.
>>>
Starting Location: Washington
Destination: Baltimore
URL: https://www.mapquestapi.com/directions/v2/route?
key=your_api_key&from=Washington&to=Baltimore
API Status: 0 = A successful route call.

Directions from Washington to Baltimore


Trip Duration: 00:49:19

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Kilometers: 61.32
Fuel Used (Ltr): 6.24
=============================================
Start out going north on 6th St/US-50 E/US-1 N toward Pennsylvania Ave/US-1 Alt N.
(1.28 km)
Turn right onto New York Ave/US-50 E. Continue to follow US-50 E (Crossing into
Maryland). (7.51 km)
Take the Balt-Wash Parkway exit on the left toward Baltimore. (0.88 km)
Merge onto MD-295 N. (50.38 km)
Turn right onto W Pratt St. (0.86 km)
Turn left onto S Calvert St/MD-2. (0.43 km)
Welcome to BALTIMORE, MD. (0.00 km)
=============================================

Starting Location: quit


>>>

Note: To see the JSON for the above output, you can copy the URL in a browser tab. However, you will need
to replace your_api_key with the MapQuest API key you obtain in Part 3.

Part 3: Get a MapQuest API Key


Before building the application, you need to complete the following steps to get a MapQuest API key.
a. Go to: https://developer.mapquest.com/.
b. Click Sign Up at the top of the page.
c. Fill out the form to create a new account. For Company, enter Cisco Networking Academy Student.
d.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

e. After clicking Sign Me Up, you are redirected to the Manage Keys page. If you are redirected elsewhere,
click Manage Keys from the list of options on the left.
f. Click Approve All Keys.
g. Expand My Application.
h. Copy your Consumer Key to a text file for future use. This will be the key you use for the rest of this lab.
Note: MapQuest may change the process for obtaining a key. If the steps above are no longer valid, search
the internet for “steps to generate mapquest api key”.

Part 4: Build the Basic MapQuest Direction Application


In this Part, you will create a Python script to send a URL request to the MapQuest directions API. You will
then test your API call. Throughout the rest of this lab, you will build your script in parts, saving the file with a
new name each time. This will help with learning the pieces of the application as well as provide you a series
of scripts that you can return to if you run into any problems in the current version of your application.

Step 1: Create a New File in VS Code.


You can use any tools you want to enter in Python commands and execute the Python code. However, this
lab will demonstrate building the application in VS Code.
a. Open VS Code. There is a shortcut on the Desktop, for your convenience.
b. Select File > Open Folder...
c. Navigate to the ~/labs/devnet-src/mapquest directory and click OK. This directory is currently empty
and is where you will store each iteration of your application.
d. Select File > New File.
e. Select File > Save as… and name the file mapquest_parse-json_1.py and click Save.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

f.

Step 2: Importing modules for the application.


To begin your script for parsing JSON data, you will need to import two modules from the Python library:
requests and urllib.parse. The requests module provides functions for retrieving JSON data from a URL.
The urllib.parse module provides a variety of functions that will enable you to parse and manipulate the
JSON data you receive from a request to a URL.
a. Add the following import statements at the top of your script.
import urllib.parse
import requests

b. Select Terminal > New Terminal to open a Terminal inside VS Code.


c. Save and run your script. You should get no errors. You should save and run your scripts often to test
code functionality.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_1.py
devasc@labvm:~/labs/devnet-src/mapquest$

Step 3: Build the URL for the request to the MapQuest directions API.
The first step in creating your API request is to construct the URL that your application will use to make the
call. Initially, the URL will be the combination of the following variables:
 main_api - the main URL that you are accessing
 orig - the parameter to specify your point of origin
 dest - the parameter to specify your destination
 key - the MapQuest API key you retrieved from the developer website
a. Create variables to build the URL that will be sent in the request. In the following code, replace
your_api_key with the Consumer Key you copied from your MapQuest developer account.
main_api = "https://www.mapquestapi.com/directions/v2/route?"

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

orig = "Washington, D.C."


dest = "Baltimore, Md"
key = "your_api_key"

b. Combine the four variables main_api, orig, dest, and key to format the requested URL. Use the
urlencode method to properly format the address value. This function builds the parameters part of the
URL and converts possible special characters in the address value into acceptable characters (e.g. space
into “+” and a comma into “%2C”).
c.

url = main_api + urllib.parse.urlencode({"key":key, "from":orig, "to":dest})

d. Create a variable to hold the reply of the requested URL and print the returned JSON data. The
json_data variable holds a Python’s Dictionary representation of the json reply of the get method of the
requests module. The requests.get will make the API call to the MapQuest API. The print statement will
be used temporarily to check the returned data. You will replace this print statement with more
sophisticated display options later in the lab.
json_data = requests.get(url).json()
print(json_data)

e. Your final code should look like this, but with a different value for the key.
import urllib.parse
import requests

main_api = "https://www.mapquestapi.com/directions/v2/route?"
orig = "Washington, D.C."
dest = "Baltimore, Md"
key = "fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ" #Replace with your MapQuest key

url = main_api + urllib.parse.urlencode({"key":key, "from":orig, "to":dest})

json_data = requests.get(url).json()
print(json_data)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Step 4: Test the URL request.


a. Save and run your mapquest_parse-json_1.py script and verify it works.
b. Troubleshoot your code, if necessary. Although your output might be slightly different, you should get a
JSON response similar to the following. Notice that the output is a dictionary with two key/value pairs. The
value for the key route is another dictionary that includes additional dictionaries and lists. The key info
includes the statuscode key/value pair that you will use later in the lab.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_1.py
{'route': {'hasTollRoad': False, 'hasBridge': True, 'boundingBox': {'lr': {'lng': -
76.612137, 'lat': 38.892063}, 'ul': {'lng': -77.019913, 'lat': 39.290443}},
'distance': 38.089, 'hasTimedRestriction': False, 'hasTunnel': False, 'hasHighway':
True, 'computedWaypoints': [], 'routeError': {'errorCode': -400, 'message': ''},
'formattedTime': '00:49:29', 'sessionId': '5eadfc17-00ee-5f21-02b4-1a24-0647e6e69816',
'hasAccessRestriction': False, 'realTime': 2915, 'hasSeasonalClosure': False,
'hasCountryCross': False, 'fuelUsed': 1.65, 'legs': [{'hasTollRoad': False,
'hasBridge': True, 'destNarrative': 'Proceed to BALTIMORE, MD.', 'distance': 38.089,
'hasTimedRestriction': False, 'hasTunnel': False, 'hasHighway': True, 'index': 0,
'formattedTime': '00:49:29', 'origIndex': -1, 'hasAccessRestriction': False,
'hasSeasonalClosure': False, 'hasCountryCross': False, 'roadGradeStrategy': [[]],
'destIndex': 3, 'time': 2969, 'hasUnpaved': False, 'origNarrative': '', 'maneuvers':
[{'distance': 0.792, 'streets': ['6th St', 'US-50 E', 'US-1 N'], 'narrative': 'Start
out going north on 6th St/US-50 E/US-1 N toward Pennsylvania Ave/US-1 Alt N.',
'turnType': 0, 'startPoint': {'lng': -77.019913, 'lat': 38.892063}, 'index': 0,
'formattedTime': '00:02:06', 'directionName': 'North', 'maneuverNotes': [], 'linkIds':
[], 'signs': [{'extraText': '', 'text': '50', 'type': 2, 'url':
'http://icons.mqcdn.com/icons/rs2.png?n=50&d=EAST', 'direction': 8}, {'extraText': '',
'text': '1', 'type': 2, 'url': 'http://icons.mqcdn.com/icons/rs2.png?n=1&d=NORTH',
<<<<< >>>>>
output omitted
<<<<< >>>>>
'geocodeQuality': 'CITY', 'adminArea1Type': 'Country', 'adminArea3Type': 'State',
'latLng': {'lng': -76.61233, 'lat': 39.29044}}], 'time': 2969, 'hasUnpaved': False,
'locationSequence': [0, 1], 'hasFerry': False}, 'info': {'statuscode': 0, 'copyright':
{'imageAltText': '© 2019 MapQuest, Inc.', 'imageUrl':
'http://api.mqcdn.com/res/mqlogo.gif', 'text': '© 2019 MapQuest, Inc.'}, 'messages':
[]}}

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

devasc@labvm:~/labs/devnet-src/mapquest$

c. Change the orig and dest variables. Rerun the script to get different results. To ensure the results you
want, it is best to include both the city and the state for cities in the USA. When referring to cities in other
countries, you can usually use either the English name for the city and country or the native name. For
example:
orig = "Rome, Italy"
dest = "Frascati, Italy"

or
orig = "Roma, Italia"
dest = "Frascati, Italia"

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Step 5: Print the URL and check the status of the JSON request.
Now that you know the JSON request is working, you can add some more functionality to the application.
a. Save your script as mapquest_parse-json_2.py.
b. Delete the print(json_data) statement as you no longer need to test that the request is properly
formatted.
c. Add the statements below, which will do the following:
o Print the constructed URL so that the user can see the exact request made by the application.
o Parse the JSON data to obtain the statuscode value.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

o Start an if loop that checks for a successful call, which is indicated by a returned value of 0. Add a
print statement to display the statuscode value and its meaning. The \n adds a blank line below the
output.
Later in this lab, you will add elif and else statements for different statuscode values.
print("URL: " + (url))

json_data = requests.get(url).json()
json_status = json_data["info"]["statuscode"]

if json_status == 0:
print("API Status: " + str(json_status) + " = A successful route call.\n")

Step 6: Test status and URL print commands.


a. The example here uses the following parameters.
orig = "Washington, D.C."
dest = "Baltimore, Md"

b. Save and run your mapquest_parse-json_2.py script and verify it works. Troubleshoot your code, if
necessary. You should get output similar to the following. Notice your key is embedded in the URL
request.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_2.py
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

devasc@labvm:~/labs/devnet-src/mapquest$

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Step 7: Add User input for starting location and destination.


You have used static values for the location variables. However, the application requires that the user input
these. Complete the following steps to update your application:
a. Save your script as mapquest_parse-json_3.py.
b. Delete the current orig and dest variables.
c. Rewrite the orig and dest to be within a while loop in which it requests user input for the starting location
and destination. The while loop allows the user to continue to make requests for different directions. Add
the following code, highlighted below, after the key parameter. Be sure all the remaining code is correctly
indented within the while loop.
import urllib.parse
import requests

main_api = "https://www.mapquestapi.com/directions/v2/route?"
key = "fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ"

while True:
orig = input("Starting Location: ")
dest = input("Destination: ")
url = main_api + urllib.parse.urlencode({"key": key, "from":orig, "to":dest})
print("URL: " + (url))
json_data = requests.get(url).json()
json_status = json_data["info"]["statuscode"]
if json_status == 0:
print("API Status: " + str(json_status) + " = A successful route call.\n")

Step 8: Test user input functionality.


Run your mapquest_parse-json_3.py script and verify it works. Troubleshoot your code, if necessary. You
should get output similar to what is shown below. To end the program, enter Ctrl+C. You will get a
KeyboardInterrupt error as shown in the output below. To stop the application more gracefully, you will add
quit functionality in the next step.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_3.py
Starting Location: Washington, D.C.
Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

Starting Location: ^CTraceback (most recent call last):


File "mapquest_parse-json_3.py", line 9, in <module>
orig = input("Starting Location: ")

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 10 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

KeyboardInterrupt

devasc@labvm:~/labs/devnet-src/mapquest$

Step 9: Add quit functionality to the application.


Instead of forcing the application to quit with a keyboard interrupt, you will add the ability for the user to enter
q or quit as keywords to quit the application. Complete the following steps to update your application:
a. Save your script as mapquest_parse-json_4.py.
b. Add an if statement after each location variable to check if the user enters q or quit, as shown below.
while True:
orig = input("Starting Location: ")
if orig == "quit" or orig == "q":
break
dest = input("Destination: ")
if dest == "quit" or dest == "q":
break

Step 10: Test the quit functionality.


Run your mapquest_parse-json_4.py script four times to test each location variable. Verify that both quit
and q will end the application. Troubleshoot your code, if necessary. You should get output similar to the
following.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_4.py
Starting Location: q

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 11 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_4.py


Starting Location: quit
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_4.py
Starting Location: Washington, D.C
Destination: q
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_4.py
Starting Location: Washington, D.C.
Destination: quit
devasc@labvm:~/labs/devnet-src/mapquest$

Step 11: Display the JSON data in JSONView.


The Chromium browser in the DEVASC VM includes the JSONView extension. You can use this to view a
JSON object in a readable, colored, and collapsible format.
a. Run your mapquest_parse-json_4.py again and copy the code returned for the URL. Do not use the
code below. Your result will include your API key.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_4.py
Starting Location: Washington, D.C.
Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

Starting Location: quit

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 12 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

devasc@labvm:~/labs/devnet-src/mapquest$
b. Paste the URL in the Chromium browser address field
c.

.
d. Collapse the JSONView data by selecting the dash "-" before route, you will see that there are two root
dictionaries: route and info.
{
- route:{
hasTollRoad: false,
hasBridge: true,
<output omitted>

You will see that there are two root dictionaries: route and info. Notice that info has the statuscode
key/value paired used in your code.
{
+ route: {},
- info: {
statuscode: 0,
- copyright: {

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 13 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

imageAltText: "© 2019 MapQuest, Inc.",


imageUrl: "http://api.mqcdn.com/res/mqlogo.gif",
text: "© 2019 MapQuest, Inc."
},
messages: [ ]
}
}

e. Expand the route dictionary (click on the plus sign "+" before route) and investigate the rich data. There
are values to indicate whether the route has toll roads, bridges, tunnels, highways, closures, or crosses
into other countries. You should also see values for distance, the total time the trip will take, and fuel
usage. To parse and display this data in your application, you would specify the route dictionary and then
select key/value pair you want to print. You will do some parsing of the route dictionary in the next part of
the lab.

Part 5: Upgrade the MapQuest Directions Application with More Features


In this Part, you will add additional features to your MapQuest Directions Application to provide more
information to the user. You will include some trip summary information and then a list of the directions parsed
from the legs dictionary. As a final step, you will add some basic error checking to validate user input.

Step 1: Display trip summary information to include duration, distance, and fuel used.
a. Save your script as mapquest_parse-json_5.py.
b. Below the API status print command, add several print statements that display the from and to locations,
as well as the formattedTime, distance, and fuelUsed keys.
The additional statements also include print statements that will display a double line before the next
request for a starting location. Make sure these statements are embedded in the while True function.
if json_status == 0:
print("API Status: " + str(json_status) + " = A successful route call.\n")
print("=============================================")
print("Directions from " + (orig) + " to " + (dest))
print("Trip Duration: " + (json_data["route"]["formattedTime"]))
print("Miles: " + str(json_data["route"]["distance"]))
print("Fuel Used (Gal): " + str(json_data["route"]["fuelUsed"]))
print("=============================================")

c. Save and run mapquest_parse-json_5.py to see the following output.


devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_5.py

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 14 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Starting Location: Washington, D.C.


Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

=============================================
Directions from Washington, D.C. to Baltimore, Md
Trip Duration: 00:49:29
Miles: 38.089
Fuel Used (Gal): 1.65
=============================================
Starting Location: q
devasc@labvm:~/labs/devnet-src/mapquest$

d. By defauilt, MapQuest uses the imperial system and there is not a request parameter to change data to
the metric system. Therefore, you should probably convert your application to display metric values, as
shown below.
print("Kilometers: " + str((json_data["route"]["distance"])*1.61))
print("Fuel Used (Ltr): " + str((json_data["route"]["fuelUsed"])*3.78))

e. Run the modified mapquest_parse-json_5.py script to see the following output:


devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_5.py
Starting Location: Washington, D.C.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 15 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

=============================================
Directions from Washington, D.C. to Baltimore, Md
Trip Duration: 00:49:29
Kilometers: 61.32329
Fuel Used (Ltr): 6.236999999999999
=============================================
Starting Location: q
devasc@labvm:~/labs/devnet-src/mapquest$

f. The extra decimal places for Kilometers and Fuel Used are not helpful. Use the "{:.2f}".format argument
to format the float values to 2 decimal places before converting them to string values, as shown below.
Each statement should be on one line.
print("Kilometers: " + str("{:.2f}".format((json_data["route"]
["distance"])*1.61)))
print("Fuel Used (Ltr): " + str("{:.2f}".format((json_data["route"]
["fuelUsed"])*3.78)))

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 16 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Step 2: Test the parsing and formatting functionality.


Save and run your mapquest_parse-json_5.py script to verify it works. Troubleshoot your code, if
necessary. Make sure you have all the proper opening and closing parentheses. You should get output
similar to the following.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_5.py
Starting Location: Washington, D.C.
Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

=============================================
Directions from Washington, D.C. to Baltimore, Md
Trip Duration: 00:49:29
Kilometers: 61.32
Fuel Used (Ltr): 6.24
=============================================
Starting Location: q
devasc@labvm:~/labs/devnet-src/mapquest$

Step 3: Inspect the maneuvers list in the JSON data.


a. Now you are ready to display the step-by-step directions from the starting location to the destination.
Return to the Chromium browser where earlier you viewed the output in JSONView. If you closed the
browser, copy the URL from last time you ran the program and paste it into the browser address bar.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 17 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

b. Inside the route dictionary, locate the legs list. The legs list includes one big dictionary with most of the
JSON data. Find the maneuvers list and collapse each of the seven dictionaries inside, as shown below
(click the "-" minus sign to toggle it to a "+" plus sign). If you are using different locations, you will
probably have a different number of maneuver dictionaries.
- legs: [
- {
hasTollRoad: false,
hasBridge: true,
destNarrative: "Proceed to BALTIMORE, MD.",
distance: 38.089,
hasTimedRestriction: false,
hasTunnel: false,
hasHighway: true,
index: 0,
formattedTime: "00:49:29",
origIndex: -1,
hasAccessRestriction: false,
hasSeasonalClosure: false,
hasCountryCross: false,
- roadGradeStrategy: [
[ ]
],
destIndex: 3,
time: 2969,
hasUnpaved: false,
origNarrative: "",
- maneuvers: [
+ {…},
+ {…},
+ {…},
+ {…},
+ {…},
+ {…},
+ {…}
],
hasFerry: false
}
],
- options: {

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 18 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

c. Expand the first dictionary in the maneuvers list. Each dictionary contains a narrative key with a value,
such as “Start out going north...”, as shown below. You need to parse the JSON data to extract the value
for the narrative key to display inside your application.
- legs: [
- {
hasTollRoad: false,
hasBridge: true,
destNarrative: "Proceed to BALTIMORE, MD.",
distance: 38.089,
hasTimedRestriction: false,
hasTunnel: false,
hasHighway: true,
index: 0,
formattedTime: "00:49:29",
origIndex: -1,
hasAccessRestriction: false,
hasSeasonalClosure: false,
hasCountryCross: false,
- roadGradeStrategy: [
[ ]
],

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 19 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

destIndex: 3,
time: 2969,
hasUnpaved: false,
origNarrative: "",
- maneuvers: [
- {
distance: 0.792,
- streets: [
"6th St",
"US-50 E",
"US-1 N"
],
narrative: "Start out going north on 6th St/US-50E/US-1 N toward
Pennsylvania Ave/US-1 Alt N.",
turnType: 0,
- startPoint: {
lng: -77.019913,
lat: 38.892063
},
index: 0,
formattedTime: "00:02:06",
directionName: "North",
maneuverNotes: [ ],
linkIds: [ ],
- signs: [
- {
extraText: "",
ext: "50",
type: 2,
<output omitted>

Note: Word wrap was added for the value in the narrative for display purposes.

Step 4: Add a for loop to iterate through the maneuvers JSON data.
Complete the following steps to upgrade the application to display the value for the narrative key. You will do
this by creating a for loop to iterate through the maneuvers list, displaying the narrative value for each
maneuver from starting location to destination.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 20 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

a. Save your script as mapquest_parse-json_6.py.


b. Add a for loop, highlighted below, after the second double line print statement. The for loop iterates
through each maneuvers list and does the following:
1) Prints the narrative value.
2) Converts miles to kilometers with *1.61.
3) Formats the kilometer value to print only two decimal places with the "{:.2f}".format function.
c. Add a print statement that will display a double line before the application asks for another starting
location, as shown below.
Note: The double line print statement is not indented within the for loop. It therefore is part of the previous
if statement that checks the statuscode parameter.
print("Fuel Used (Ltr): " + str("{:.2f}".format((json_data["route"]["fuelUsed"])*3.78)))
print("=============================================")
for each in json_data["route"]["legs"][0]["maneuvers"]:
print((each["narrative"]) + " (" + str("{:.2f}".format((each["distance"])*1.61) + " km)"))
print("=============================================\n")

Step 5: Activity - Test the JSON iteration.


Save and run your mapquest_parse-json_6.py script to verify it works. Troubleshoot your code, if
necessary. You should get an output similar to the following:
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_6.py
Starting Location: Washington, D.C.
Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

=============================================
Directions from Washington, D.C. to Baltimore, Md
Trip Duration: 00:49:29
Kilometers: 61.32
Fuel Used (Ltr): 6.24
=============================================
Start out going north on 6th St/US-50 E/US-1 N toward Pennsylvania Ave/US-1 Alt N.
(1.28 km)
Turn right onto New York Ave/US-50 E. Continue to follow US-50 E (Crossing into
Maryland). (7.51 km)
Take the Balt-Wash Parkway exit on the left toward Baltimore. (0.88 km)
Merge onto MD-295 N. (50.38 km)
Turn right onto W Pratt St. (0.86 km)
Turn left onto S Calvert St/MD-2. (0.43 km)
Welcome to BALTIMORE, MD. (0.00 km)
=============================================

Starting Location: q
devasc@labvm:~/labs/devnet-src/mapquest$

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 21 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Step 6: Check for invalid user input.


Now you are ready to add one final feature to your application to report an error when the user enters invalid
data. Recall that you started an if loop to make sure the returned statuscode equals 0 before parsing the
JSON data:
json_status = json_data["info"]["statuscode"]

if json_status == 0:
print("API Status: " + str(json_status) + " = A successful route call.\n")

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 22 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

But what happens if the statuscode is not equal to 0? For example, the user might enter an invalid location or
might not enter one or more locations. If so, then the application displays the URL and asks for a new starting
location. The user has no idea what happened.
a. To cause your application to fail without user notification, try the following values in your application. You
should see similar results.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_6.py
Starting Location: Washington, D.C.
Destination: Beijing, China
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Beijing%2C+China
Starting Location: Washington, D.C.
Destination: Bal
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Bal
Starting Location: q
devasc@labvm:~/labs/devnet-src/mapquest$

b. Copy one of the URLs to a Chromium browser tab. Notice that the only entry in route dictionary is a
routeError dictionary with the errorCode 2. In the info dictionary, the statuscode is 402. Therefore, your
if loop never executed the code for when the statuscode is 0.
c. Save your script as mapquest_parse-json_7.py.
d. To provide error information when statuscode is equal to 402, 611, or another value, add two elif
statements and an else statement to your if loop. Your elif and else statements must align with the
previous if statement. After the last double line print statement under the if json_status == 0, add the
following elif and else statements:
if json_status == 0:
<statements omitted>

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 23 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

for each in json_data["route"]["legs"][0]["maneuvers"]:


print((each["narrative"]) + " (" +
str("{:.2f}".format((each["distance"])*1.61) + " km)"))
print("=============================================\n")
elif json_status == 402:
print("**********************************************")
print("Status Code: " + str(json_status) + "; Invalid user inputs for one or both
locations.")
print("**********************************************\n")
elif json_status == 611:
print("**********************************************")
print("Status Code: " + str(json_status) + "; Missing an entry for one or both
locations.")
print("**********************************************\n")
else:
print("************************************************************************")
print("For Staus Code: " + str(json_status) + "; Refer to:")
print("https://developer.mapquest.com/documentation/directions-api/status-codes")
print("************************************************************************\n")

The first elif statement prints if the statuscode value is 402 for an invalid location. The second elif
statement prints if the statuscode value is 611 because the user did not provide an entry for one or both
locations. The else statement prints for all other statuscode values, such as when the MapQuest site
returns an error. The else statement ends the if/else loop and returns the application to the while loop.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 24 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Part 6: Test Full Application Functionality


Run your mapquest_parse-json_7.py script and verify it works. Troubleshoot your code, if necessary. Test
all the features of the application. You should get output similar to the following.
devasc@labvm:~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_7.py
Starting Location: Washington, D.C.
Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Baltimore%2C+Md
API Status: 0 = A successful route call.

=============================================
Directions from Washington, D.C. to Baltimore, Md

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 25 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Trip Duration: 00:49:29


Kilometers: 61.32
Fuel Used (Ltr): 6.24
=============================================
Start out going north on 6th St/US-50 E/US-1 N toward Pennsylvania Ave/US-1 Alt N.
(1.28 km)
Turn right onto New York Ave/US-50 E. Continue to follow US-50 E (Crossing into
Maryland). (7.51 km)
Take the Balt-Wash Parkway exit on the left toward Baltimore. (0.88 km)
Merge onto MD-295 N. (50.38 km)
Turn right onto W Pratt St. (0.86 km)
Turn left onto S Calvert St/MD-2. (0.43 km)
Welcome to BALTIMORE, MD. (0.00 km)
=============================================

Starting Location: Moscow, Russia


Destination: Beijing, China
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Moscow%2C+Russia&to=Beijing%2C+China
API Status: 0 = A successful route call.

=============================================
Directions from Moscow, Russia to Beijing, China
Trip Duration: 84:31:10
Kilometers: 7826.83
Fuel Used (Ltr): 793.20
=============================================
Start out going west on Кремлёвская набережная/Kremlin Embankment. (0.37 km)
Turn slight right onto ramp. (0.15 km)
Turn slight right onto Боровицкая площадь. (0.23 km)
<output omitted>
Turn slight left onto 前门东大街/Qianmen East Street. (0.31 km)
Turn left onto 广场东侧路/E. Guangchang Rd. (0.82 km)
广场东侧路/E. Guangchang Rd becomes 东长安街/E. Chang'an Str. (0.19 km)
Welcome to BEIJING. (0.00 km)
=============================================

Starting Location: Washington, D.C.


Destination: Beijing, China
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Beijing%2C+China
**********************************************
Status Code: 402; Invalid user inputs for one or both locations.
**********************************************

Starting Location: Washington, D.C.


Destination: Bal
URL: https://www.mapquestapi.com/directions/v2/route?
key=fZadaFOY22VIEEemZcBFfxl5vjSXIPpZ&from=Washington%2C+D.C.&to=Bal

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 26 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

**********************************************
Status Code: 402; Invalid user inputs for one or both locations.
**********************************************

Starting Location: Washington, D.C.


Destination:
URL: https://www.mapquestapi.com/directions/v2/route?
key=ANUqwkHlgDv1vlsyBPtVrFeX8uu6agjA&from=Washington%2C+D.C.&to=
**********************************************
Status Code: 611; Missing an entry for one or both locations.
**********************************************

Starting Location: quit


devasc@labvm:~/labs/devnet-src/mapquest$

Devasc@samuelgh~/labs/devnet-src/mapquest$ python3 mapquest_parse-json_7.py


Starting Location: Washington, D.C.
Destination: Baltimore, Md
URL: https://www.mapquestapi.com/directions/v2/route?
key=eaQLGDSncFjeJvbI3vm45DgD5NXoa2tE&from=Washington%2C+D.C.&to=Baltimore
%2C+Md
API Status: 0 = A successful route call.

=============================================
Directions from Washington, D.C. to Baltimore, Md
Trip Duration: 00:48:47
Kilometers: 65.56
=============================================
Head toward Jefferson Dr SW on 14th St NW (US-1). Go for 0.2 mi. (0.31 km)
Turn left onto Independence Ave SW. Go for 0.4 mi. (0.67 km)
Turn slightly right and take ramp onto 9th St SW toward I-395 S. Go for 0.3
mi. (0.54 km)
Take left ramp onto I-395 N (Southwest Fwy) toward I-695. Go for 0.3 mi. (0.49
km)
Continue on I-695 E (Southeast Fwy). Go for 1.9 mi. (3.04 km)
Take exit 2B toward US-50 onto DC-295 N (Anacostia Fwy). Go for 4.5 mi. (7.19
km)
Continue on MD-295 N. Go for 31.6 mi. (50.87 km)
Keep left onto Russell St (MD-295 N). Go for 0.6 mi. (0.89 km)
Turn right onto W Pratt St toward I-83. Go for 0.6 mi. (1.05 km)
Turn left onto Commerce St. Go for 430 ft. (0.13 km)
Continue on Commerce St. Go for 0.1 mi. (0.21 km)
Continue on N Holliday St. Go for 282 ft. (0.09 km)
Turn right onto E Fayette St. Go for 272 ft. (0.08 km)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 27 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Arrive at E Fayette St. (0.00 km)


=============================================

Starting Location: Moscow, Russia


Destination: Beijing, China
URL: https://www.mapquestapi.com/directions/v2/route?
key=eaQLGDSncFjeJvbI3vm45DgD5NXoa2tE&from=Moscow%2C+Russia&to=Beijing%2C+China
API Status: 0 = A successful route call.

=============================================
Directions from Moscow, Russia to Beijing, China
Trip Duration: 81:37:21
Kilometers: 7500.94
=============================================
Head toward Mokhovaya ulitsa on Tverskaya ulitsa. Go for 33 ft. (0.01 km)
Turn left onto ulitsa Okhotniy Ryad. Go for 0.2 mi. (0.30 km)
Continue on Teatral'niy proezd. Go for 0.3 mi. (0.42 km)
Turn left onto Lubyanskaya ploshchad' toward Bol'shaya Lubyanka
ulitsa/Sretenka ulitsa. Go for 486 ft. (0.15 km)
Continue on ulitsa Bol'shaya Lubyanka. Go for 0.5 mi. (0.73 km)
Turn right onto Sretenskiy bul'var. Go for 0.2 mi. (0.38 km)
Make a U-Turn onto Turgenevskaya ploshchad'. Go for 371 ft. (0.11 km)
Turn right onto prospekt Akademika Sakharova. Go for 0.6 mi. (0.95 km)
Continue on ulitsa Mashi Poryvaevoy. Go for 0.3 mi. (0.43 km)
Turn right onto Kalanchyovskaya ulitsa. Go for 371 ft. (0.11 km)
Turn left onto Komsomol'skaya ploshchad' toward Komsomol'skaya square. Go for
0.8 mi. (1.33 km)
Turn right onto ulitsa Gavrikova toward Spartakovskaya
ploshchad'/Spartakovskaya square/3-e kol'tso/M8/Mira pr-t/M7/Entuziastov sh.
Go for 223 ft. (0.07 km)
Keep right toward 3-e kol'tso-Nalevo/M8/Mira pr-t. Go for 269 ft. (0.08 km)
Continue on ulitsa Gavrikova. Go for 0.2 mi. (0.27 km)
Turn right onto Lesnoryadskiy pereulok. Go for 0.4 mi. (0.63 km)
Turn right onto Rusakovskaya ulitsa. Go for 0.1 mi. (0.17 km)
Turn right onto ulitsa Zhebrunova. Go for 0.5 mi. (0.79 km)
Continue on ulitsa Matrosskaya Tishina. Go for 194 ft. (0.06 km)
Turn right onto ulitsa Gastello. Go for 0.5 mi. (0.83 km)
Take ramp toward Preobrazhenskaya naberezhnaya. Go for 466 ft. (0.14 km)
Turn right onto Semyonovskaya naberezhnaya. Go for 125 ft. (0.04 km)
Continue on Preobrazhenskaya naberezhnaya. Go for 56 ft. (0.02 km)
Turn right and take ramp. Go for 174 ft. (0.05 km)
Turn left toward Elektrozavodskaya ulitsa. Go for 75 ft. (0.02 km)
Turn left onto Elektrozavodskaya ulitsa. Go for 0.1 mi. (0.19 km)
Turn right onto ploshchad' Zhuravlyova. Go for 0.1 mi. (0.17 km)
Continue on Malaya Semyonovskaya ulitsa. Go for 0.4 mi. (0.64 km)
Turn right onto Semyonovskiy pereulok. Go for 449 ft. (0.14 km)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 28 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Turn left onto Izmaylovskaya ulitsa. Go for 0.2 mi. (0.25 km)
Turn right onto ulitsa Izmaylovskiy Val. Go for 0.1 mi. (0.17 km)
Turn left onto Semyonovskaya ploshchad' toward Shcherbakovskaya
ulitsa/Shcherbakovskaya street. Go for 0.1 mi. (0.23 km)
Continue on Shcherbakovskaya ulitsa toward Ibragimova ulitsa/Ibragimova
street/Mazhorov pereulok/Mazhorov side-street. Go for 0.8 mi. (1.27 km)
Continue on Izmaylovskoe shosse. Go for 266 ft. (0.08 km)
Turn right and take ramp onto Severo-Vostochnaya Khorda. Go for 1.5 mi. (2.44
km)
Take the exit toward Entuziastov sh./M7/Svobodniy pr-t onto shosse
Entuziastov. Go for 49.5 mi. (79.72 km)
Keep left onto Gor'kovskoe shosse (M7). Go for 16.0 mi. (25.78 km)
Turn right and take ramp onto M12. Go for 36.4 mi. (58.60 km)
Take the exit onto M7 (Volga). Go for 0.2 mi. (0.37 km)
Take ramp onto Volga (M7) toward Murom/N.Novgorod. Go for 34.0 mi. (54.66 km)
Take ramp onto Volga (M7) toward Nizh. Novgorod/Nizh. Novgorod. Go for 110 mi.
(176.65 km)
Take ramp onto M7 (Yuzhniy obkhod Nizhnego Novgoroda) toward
Avtozavod/Pavlovo/Kazan'. Go for 33.0 mi. (53.15 km)
Take the 1st exit from roundabout onto 22K-0007 toward Kazan'. Go for 4.3 mi.
(6.97 km)
Take ramp onto Volga (M7) toward Kazan'. Go for 147 mi. (237.33 km)
Take the 2nd exit from roundabout onto Volga (M7) toward Ufa/Ufa. Go for 229
mi. (369.21 km)
Turn right onto Orlovskoe kol'tso (M7) toward Ufa/Ufa. Go for 522 ft. (0.16
km)
Keep right onto Menzelinskiy trakt (M7). Go for 2.1 mi. (3.39 km)
Take the 1st exit from roundabout onto Menzelinskiy trakt (M7) toward Ufa. Go
for 1.5 mi. (2.34 km)
Take the 1st exit from roundabout onto Metallurgicheskaya ulitsa (M7). Go for
1.6 mi. (2.55 km)
Turn right onto Volga (M7). Go for 158 mi. (254.61 km)
Take ramp onto E017 toward zapovednik Shul'gan-Tash/Shulgan-Tash state nature
reserve/Gornolyzhnye Tsentry/Ski Centers. Go for 16.6 mi. (26.79 km)
Keep left onto R240 toward Ufa/M5/Chelyabinsk. Go for 0.2 mi. (0.38 km)
Take ramp onto Ural (M5) toward Ufa/Chelyabinsk. Go for 250 mi. (401.83 km)
Take ramp onto Baykal (AH6/AH7) toward Troitsk. Go for 10.1 mi. (16.21 km)
Continue on 75K-205. Go for 0.4 mi. (0.58 km)
Take ramp onto Baykal (AH6/AH7) toward Chelyabinsk/Kurgan. Go for 2.9 mi.
(4.64 km)
Take ramp onto Baykal (AH6/AH7) toward Ekaterinburg/Kurgan. Go for 11.2 mi.
(18.10 km)
Continue on Baykal (AH6/AH7) toward Ekaterinburg/M51/Kurgan. Go for 15.6 mi.
(25.13 km)
Take ramp onto Irtysh (AH6) toward Kurgan. Go for 62.3 mi. (100.28 km)
Take the 2nd exit from roundabout onto Irtysh (AH6) toward Omsk. Go for 28.1
mi. (45.28 km)
Continue on Irtysh (AH6) toward Kurgan. Go for 55.3 mi. (89.11 km)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 29 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Pass 3 roundabouts and continue on Irtysh (AH6). Go for 86.1 mi. (138.66 km)
Take the 2nd exit from roundabout onto Irtysh (AH6) toward Omsk. Go for 29.1
mi. (46.87 km)
Take the 2nd exit from roundabout onto Irtysh (AH6) toward
M51/Omsk/Petropavlovsk. Go for 13.9 mi. (22.38 km)
Continue on M-51. Go for 18.9 mi. (30.35 km)
Keep left onto M-51. Go for 18.6 mi. (29.88 km)
Turn left toward Ombi. Go for 0.1 mi. (0.21 km)
Keep right onto M-51 toward Ombi. Go for 161 ft. (0.05 km)
Turn right onto M-51. Go for 2.7 mi. (4.32 km)
Make a U-Turn onto M-51. Go for 1.4 mi. (2.32 km)
Take the 2nd exit from roundabout onto M-51 toward Ombi. Go for 1.6 mi. (2.65
km)
Take the 3rd exit from roundabout onto M-51 toward Ombi. Go for 74.8 mi.
(120.45 km)
Continue on Irtysh (AH6). Go for 77.5 mi. (124.75 km)
Turn right and take ramp onto Irtysh (AH6) toward Pavlodar/A320/Novosibirsk.
Go for 20.0 mi. (32.17 km)
Pass 2 roundabouts and continue on Irtysh (AH6). Go for 50.4 mi. (81.20 km)
Take the 1st exit from roundabout onto Irtysh (AH6) toward Novosibirsk. Go for
3.1 mi. (4.93 km)
Take the 2nd exit from roundabout onto Irtysh (AH6) toward Novosibirsk. Go for
3.2 mi. (5.22 km)
Take the 2nd exit from roundabout onto Irtysh (AH6) toward Novosibirsk. Go for
323 mi. (520.15 km)
Keep left onto Severniy Ob'ezd (AH6) toward Kemerovo/R255/Tomsk. Go for 28.6
mi. (46.08 km)
Take ramp onto Severniy Ob'ezd (AH6). Go for 134 mi. (215.72 km)
Take the 3rd exit from roundabout onto Sibir' (R255). Go for 12.5 mi. (20.15
km)
Continue on Sevskaya ulitsa. Go for 0.1 mi. (0.19 km)
Turn left onto ulitsa Marata toward Mariinsk/R-255/Yashkino. Go for 331 ft.
(0.10 km)
Continue on Prigorodnaya ulitsa toward Tsentr. Go for 3.1 mi. (4.98 km)
Continue on Zheleznodorozhnaya ulitsa. Go for 0.6 mi. (0.92 km)
Turn right onto ulitsa Sakko. Go for 0.2 mi. (0.29 km)
Turn left onto Rabochaya ulitsa. Go for 1.0 mi. (1.60 km)
Turn right onto Krasnoarmeyskaya ulitsa toward Mariinsk/Yashkino/Tsentr. Go
for 0.8 mi. (1.25 km)
Turn left onto Kuznetskiy prospekt toward Mariinsk/R-255/Yashkino. Go for 1.0
mi. (1.61 km)
Continue on Kuznetskiy most. Go for 0.8 mi. (1.30 km)
Continue on Logovaya ulitsa. Go for 0.7 mi. (1.07 km)
Continue on ulitsa Nakhimova. Go for 12.5 mi. (20.06 km)
Turn right onto Sibir' (AH6) toward Irkutsk/Mariinsk. Go for 197 mi. (316.72
km)
Turn left toward Nagornovo. Go for 5.6 mi. (8.97 km)
Turn right toward Ostrovnaya ulitsa. Go for 0.1 mi. (0.23 km)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 30 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Continue on Ostrovnaya ulitsa. Go for 0.5 mi. (0.82 km)


Continue on ulitsa Puzanovoy. Go for 223 ft. (0.07 km)
Turn right onto ulitsa Patushinskogo. Go for 364 ft. (0.11 km)
Turn left onto ulitsa Lenina. Go for 0.2 mi. (0.37 km)
Turn right onto ulitsa Dzerzhinskogo. Go for 60.3 mi. (97.09 km)
Take the 2nd exit from roundabout onto Sibir' (AH6) toward Krasnoyarsk. Go for
34.5 mi. (55.59 km)
Take ramp onto AH6 toward Irkutsk/Tvorogovo/Kottedzhniy posyolok Skandinaviya.
Go for 94.2 mi. (151.70 km)
Take the 2nd exit from roundabout onto Sibir' (AH6) toward Kansk. Go for 51.7
mi. (83.25 km)
Continue toward Kansk. Go for 1.5 mi. (2.45 km)
Continue on Yugo-Zapadniy mikrorayon. Go for 0.3 mi. (0.48 km)
Turn right onto Okruzhnaya ulitsa toward Irkutsk/Taseevo/Aban. Go for 1.7 mi.
(2.78 km)
Take the 2nd exit from roundabout onto ulitsa Eydemana toward
Aban/Taseevo/Irkutsk. Go for 0.7 mi. (1.08 km)
Take the 2nd exit from roundabout onto ulitsa Eydemana toward
Irkutsk/Boguchany. Go for 0.5 mi. (0.87 km)
Continue on ulitsa Nekrasova. Go for 0.6 mi. (0.95 km)
Continue on Krasnopartizanskaya ulitsa. Go for 0.1 mi. (0.16 km)
Turn right onto ulitsa Kalandarashvili toward Taseevo/Boguchany/Irkutsk. Go
for 0.1 mi. (0.18 km)
Continue on ulitsa Kobrina. Go for 0.1 mi. (0.23 km)
Continue on ulitsa Pugachyova toward Taseevo/Boguchany/Irkutsk. Go for 0.3 mi.
(0.42 km)
Continue toward Irkutsk/Boguchany. Go for 0.5 mi. (0.76 km)
Take the 1st exit from roundabout onto Magistral'naya ulitsa toward Irkutsk.
Go for 1.4 mi. (2.21 km)
Take the 2nd exit from roundabout onto AH6 toward Krasnoyarsk/Irkutsk. Go for
502 ft. (0.15 km)
Turn left and take ramp onto ulitsa Dekabristov (AH6). Go for 265 mi. (425.90
km)
Turn right onto Sovetskaya ulitsa. Go for 2.0 mi. (3.26 km)
Continue on ulitsa Lenina. Go for 85 ft. (0.03 km)
Turn left onto ulitsa Lenina. Go for 98 ft. (0.03 km)
Turn right onto Yubileynaya ulitsa. Go for 135 ft. (0.04 km)
Turn right onto Yubileynaya ulitsa. Go for 0.8 mi. (1.29 km)
Turn right onto 1-y Kirovskiy pereulok (AH6). Go for 27.8 mi. (44.73 km)
Continue toward Sibir'/AH6. Go for 164 ft. (0.05 km)
Take the 2nd exit from roundabout onto Sibir' (AH6). Go for 125 mi. (201.26
km)
Take the 2nd exit from roundabout onto Sibir' (AH6) toward Irkutsk. Go for
82.4 mi. (132.62 km)
Take ramp onto Zapadniy Obkhod Irkutska (AH6) toward Chita. Go for 12.6 mi.
(20.28 km)
Continue on Zapadniy Obkhod Irkutska (AH6) toward Chita. Go for 2.1 mi. (3.35
km)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 31 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Take ramp onto Kultukskiy trakt (AH6) toward Chita/Chita. Go for 122 mi.
(195.94 km)
Continue on Baykal (AH6). Go for 145 mi. (232.85 km)
Take ramp onto A165 (AH3) toward Kyakhta. Go for 134 mi. (216.32 km)
Turn slightly right. Go for 0.4 mi. (0.58 km)
Turn left. Go for 276 ft. (0.08 km)
Turn right toward A165/AH3. Go for 36 ft. (0.01 km)
Turn right onto A165 (AH3). Go for 56 ft. (0.02 km)
Continue straight ahead. Go for 36 ft. (0.01 km)
Turn right toward Дархан Сүхбаатар. Go for 0.2 mi. (0.40 km)
Turn left onto Дархан Сүхбаатар. Go for 0.2 mi. (0.28 km)
Turn right onto Дархан Сүхбаатар. Go for 42.9 mi. (69.13 km)
Continue on Дархан-Сүхбаатар. Go for 16.5 mi. (26.50 km)
Turn left onto Дархан-Сүхбаатар. Go for 14.3 mi. (22.97 km)
Continue on A0401. Go for 1.3 mi. (2.09 km)
Continue on Улаанбаатар-Дархан. Go for 104 mi. (167.04 km)
Continue on А0401. Go for 2.2 mi. (3.59 km)
Continue on Улаанбаатар-Дархан. Go for 21.7 mi. (34.88 km)
Keep right onto А0301. Go for 387 ft. (0.12 km)
Continue on Товчооны Зам. Go for 6.3 mi. (10.07 km)
Turn right onto Enkh Tayvan Avenue. Go for 3.4 mi. (5.45 km)
Continue on Peace Avenue. Go for 4.6 mi. (7.43 km)
Keep right toward Enkh Tayvan Avenue. Go for 318 ft. (0.10 km)
Continue on Enkh Tayvan Avenue. Go for 0.2 mi. (0.24 km)
Continue on Peace Avenue. Go for 358 ft. (0.11 km)
Take the 2nd exit from roundabout onto Police Academy Avenue. Go for 0.3 mi.
(0.51 km)
Continue on Enkh Tayvan Avenue. Go for 20.6 mi. (33.12 km)
Continue on А0101. Go for 31.0 mi. (49.85 km)
Continue on А0101. Go for 7.1 mi. (11.45 km)
Continue on А0101. Go for 52.7 mi. (84.84 km)
Continue on А0101. Go for 9.9 mi. (16.01 km)
Continue on А0101. Go for 17.5 mi. (28.11 km)
Continue on А0101. Go for 60.2 mi. (96.86 km)
Turn right. Go for 436 ft. (0.13 km)
Keep left. Go for 75.8 mi. (122.06 km)
Turn left. Go for 2.1 mi. (3.32 km)
Turn left. Go for 0.3 mi. (0.49 km)
Keep right. Go for 0.6 mi. (0.94 km)
Turn right. Go for 4.4 mi. (7.00 km)
Turn left. Go for 10.7 mi. (17.21 km)
Turn left. Go for 18.8 mi. (30.32 km)
Keep right. Go for 0.5 mi. (0.77 km)
Keep right. Go for 0.5 mi. (0.83 km)
Turn right. Go for 35.5 mi. (57.22 km)

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 32 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

Turn sharp left. Go for 65.4 mi. (105.31 km)


Take the 2nd exit from roundabout. Go for 3.5 mi. (5.58 km)
Turn left. Go for 0.1 mi. (0.21 km)
Turn right. Go for 0.1 mi. (0.22 km)
Continue straight ahead. Go for 6.3 mi. (10.11 km)
Turn left. Go for 15.1 mi. (24.27 km)
Turn left. Go for 128 mi. (205.66 km)
Turn left. Go for 0.5 mi. (0.88 km)
Turn right toward 110. Go for 58.0 mi. (93.43 km)
Turn left onto 110. Go for 47.8 mi. (76.92 km)
Turn left onto 110. Go for 22.4 mi. (36.05 km)
Turn left onto 110. Go for 42.3 mi. (68.14 km)
Turn sharp right onto 207. Go for 18.0 mi. (28.91 km)
Continue on 110. Go for 107 mi. (171.78 km)
Continue on Gulouxi ST. Go for 0.1 mi. (0.21 km)
Turn right toward XI'Anmen ST. Go for 1.9 mi. (3.07 km)
Turn left onto XI'Anmen ST. Go for 0.2 mi. (0.29 km)
Turn right onto Fuyuo ST. Go for 1.1 mi. (1.79 km)
Turn left onto West Chang'an Ave. Go for 0.5 mi. (0.82 km)
Turn right onto West Chang'an Ave. Go for 0.1 mi. (0.20 km)
Arrive at West Chang'an Ave. (0.00 km)
=============================================

Starting Location: Washington, D.C.


Destination: Beijing, China
URL: https://www.mapquestapi.com/directions/v2/route?
key=eaQLGDSncFjeJvbI3vm45DgD5NXoa2tE&from=Washington%2C+D.C.&to=Beijing
%2C+China
**********************************************
Status Code: 402; Invalid user inputs for one or both locations.
**********************************************

Starting Location: Washington, D.C.


Destination: Bal
URL: https://www.mapquestapi.com/directions/v2/route?
key=eaQLGDSncFjeJvbI3vm45DgD5NXoa2tE&from=Washington%2C+D.C.&to=Bal
**********************************************
Status Code: 402; Invalid user inputs for one or both locations.
**********************************************

Starting Location: Washington, D.C.


Destination:
URL: https://www.mapquestapi.com/directions/v2/route?
key=eaQLGDSncFjeJvbI3vm45DgD5NXoa2tE&from=Washington%2C+D.C.&to=
**********************************************
Status Code: 611; Missing an entry for one or both locations.

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 33 of 34 www.netacad.com
Lab - Integrate a REST API in a Python Application

**********************************************

Starting Location: quit


Devasc@samuelgh~/labs/devnet-src/mapquest$

End of document

 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 34 of 34 www.netacad.com

You might also like