How to use APIs with Python

All right! Let's see if you can make that request to http://placekitten.com/ all on your lonesome.


You need to do two things:

  1. On line 4, create a variable called website and set it equal to calling the urlopen method on "http://placekitten.com/" (no need for the "www"!)
  2. On line 5, call the read method on website and save the result in a new variable called kittens.

The last line will then take the full kittens response you saved and display part of it.

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

(If you get a URLError, you may just need to try re-running your code. See Section 1, Exercise 1 for an example of how to deal with this error in code.)

To open the website, you'll just need

variable_name = urlopen('url')

where variable_name is website and 'url' is 'http://placekitten.com/'.

To read the response, you should use:

variable_name = page.read()

where variable_name is kittens and page is website.