This forum is now read-only. Please use our new forums at discuss.codecademy.com.

How to use APIs with Python Forum

View Course » View Exercise

416 points
F0d5daf0263d754a553905b4e37316ec?s=140&d=retro
Submitted by
nuclearfizzler
about 2 years ago

8/20 Why won't code go through?

I'm using the code, but it says I need still need to create the variable response. Please help!

var response = requests.post("https://codecademy.com/learn-http/", data = body)

0 votes

permalink

Since you're working with Python, you don't need to use the keyword "var" when defining variables; that's JS syntax.

This is the correct code:

#Import the requests module.
import requests.

#Create the body.
body = {'Name':'Eric', 'Age':'26'}

#Send the POST request and store the response in a variable.
response = requests.post("http://codecademy.com/learn-http/", data=body)

You can find more info at the requests website:
http://docs.python-requests.org/en/latest/

848 points
252f630586b97efb5f56a6b9ea92d511?s=140&d=retro
Submitted by
DarkxCoder
about 2 years ago