How to use APIs with Python
Making a Request

You saw a request in the first exercise. Now it's time for you to make your own! (Don't worry, we'll help.)

On line 1, we've imported urlopen from the urllib2 module, which is the Python way of bringing in additional functionality we'll need to make our HTTP request. A module is just a collection of extra Python tools.

On line 4, we'll use urlopen on placekitten.com in preparation for our GET request, which we make when we read from the site on line 5. (On line 6, we limit the response to specific character numbers to control the input we get backā€”this is what gives us our cat image.)

We'll need your help to complete the request!


On line 4, declare a variable, kittens, and set it equal to calling urlopen on http://placekitten.com. No need for the "www"!

On line 8, print the body variable so we can see some of the data we got back.

Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

You'll just need two lines of code. One to open the URL:

kittens = urlopen('http://placekitten.com/')

And one to print the response:

print body