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

How to use APIs with Python Forum

View Course

51 points
Bed143764a736f5ef5512b98bb5e4cd2?s=140&d=retro
Submitted by
Venkat
over 4 years ago

Making a POST Request - what's wrong and how to correct this...

Task:
set the result equal to a new variable named response.

This is my code:

import requests
requests.post(http://codecademy.com/learn-http/, data=body)
body = {'Name': 'Eric', 'Age': '26'}
response = requests.post(body)


  • Getting the following error message when try & save submit code:

Oops, try again! Did you create a new variable named response?

Traceback (most recent call last):
File "runner.py", line 125, in compilecode
File "python", line 8
requests.post(http://codecademy.com/learn-http/, data=body)
^
SyntaxError: invalid syntax


10 votes

permalink

You have two errors in your code: one is logical and other is syntax error.

First: Variable body should be defined before you use it, not after.

Second: You have to make a variable response and set it immediately to requests.post(http://codecademy.com/learn-http/, data=body)

Your code should look like this:

import requests

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

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

1241 points
518b8652017f49a6a10042be_297279719
Submitted by
Vitalijs Krumins
over 4 years ago

4 Comments

6ec8b6b2252bec177a8b4dce5b1a8688?s=140&d=retro Richard Weiss about 4 years ago

NOTE: http://codecademy.com and not http://codeacademy.com...stumped me for awhile

59780719dd1ede442e000399_610993593 Binoy Xavier Joy almost 4 years ago

Thanks! Only wasted few minutes ;)

Picture James Beveridge almost 4 years ago

Thanks Richard for this spot! I kept missing the 'a', which needed to be excluded from the URL.

526a5b3680ff33d61d001c2a_343731350 martinbluck_51b97e017c82ca3ede005f06 over 3 years ago

Thanks !


0 votes

permalink

Hello Code gurus, Still awaiting response.

Thanks, V

51 points
Bed143764a736f5ef5512b98bb5e4cd2?s=140&d=retro
Submitted by
Venkat
over 4 years ago


0 votes

permalink

Hint: This exercise can be completed by adding one line of code. Let me know if that helps. :)

4404 points
5806258092f40749a900012e_244175526
Submitted by
Adam N
over 4 years ago