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

How to use APIs with Python Forum

View Course

799 points
C728c3cc99d75859df0e316665cb8961?s=140&d=retro
Submitted by
Will
over 3 years ago

8/20 [resolved] I cannot figure out what the response variable should be set to

I cannot figure out what the response variable should be set to. My code first:

  ########## Example request #############
# POST /learn-http HTTP/1.1
# Host: www.codecademy.com
# Content-Type: text/html; charset=UTF-8
# Name=Eric&Age=26
import requests
body = {'Name': 'Eric', 'Age': '26'}
requests.post("http://codecademy.com/learn-http/", data=body)

response = requests.post()

I've tried setting response to:

 response=requests.post(data)
response=requests.post(body)
response=data
response=requests.post('Name=Eric&Age=26')

etc, etc
the response function isn't explained well and there's a bug to boot (error message displays request.get() instead of post())

Help??
Thx in advance


1 vote

Best answer

permalink

figured it out

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

but, I don't get what it's for except as a way to teach me something i'll need later. I have the data already under 'body', so why store the response in a variable

799 points
C728c3cc99d75859df0e316665cb8961?s=140&d=retro
Submitted by
Will
over 3 years ago

1 Comment

C728c3cc99d75859df0e316665cb8961?s=140&d=retro Will over 3 years ago

however the error reply message still has a bug. replace response with
response = requests.post() you'll get a request.get() error message


1 vote

permalink

there's a typo for 8/20:

http://codecademy.com/learn-http/

should be:

http://codeacademy.com/learn-http/

so, annoyingly the right spelling gives you the wrong answer. please correct this, thank you.

459 points
5159e7df39d16f5e13002a31_441213151
Submitted by
Mohammed Basith Awan
about 3 years ago

1 Comment

6ef421019c419ded332669ea5e9d2121?s=140&d=retro Simon Guy almost 3 years ago

the site is called codecademy not codeacademy in fact.


0 votes

permalink

Try this

import requests

body = {'Name': 'Eric', 'Age': '26'}

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

1492 points
56231464b62548dd8200083b_338583113
Submitted by
Ellie Adam
about 3 years ago