How to use APIs with Python
Making a POST Request

Using the Requests library, you can make a POST request by using the requests.post() method. You aren't just GETting data with a POST - you can pass your own data into the request as well, like so:

requests.post("http://placekitten.com/", data="myDataToPost")

We're going to make the same request as the one shown on line 2 through line 5. Request header lines (line 3 and line 4) are usually created automatically, so we don't have to worry about them. The body of the request on line 5 is what we will need to add to our POST.


We created the body of the request as a dictionary on line 9. Call requests.post() on the URL http://codecademy.com/learn-http/ and pass the argument data=body, as in the example above, to create the POST request; set this result equal to a new variable named response.

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

To create the POST request, you should call the method like so:
requests.post("http://codecademy.com/learn-http/", data=body)

This result should be assigned to a new object named response. Requests will automatically convert the body dictionary into the format needed for the POST request.