Fix Python – HTTP requests and JSON parsing in Python


Asked By – Arun

I want to dynamically query Google Maps through the Google Directions API. As an example, this request calculates the route from Chicago, IL to Los Angeles, CA via two waypoints in Joplin, MO and Oklahoma City, OK:,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false

It returns a result in the JSON format.

How can I do this in Python? I want to send such a request, receive the result and parse it.

Now we will see solution for issue: HTTP requests and JSON parsing in Python


I recommend using the awesome requests library:

import requests

url = ''

params = dict(

resp = requests.get(url=url, params=params)
data = resp.json() # Check the JSON Response Content documentation below

JSON Response Content:

This question is answered By – zeekay

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0