hammadu
hammadu

Reputation: 25

Http post request Python failing. (field is required)

I have been trying to do HTTP post request on the API of this website: http://text-processing.com/docs/sentiment.html

but it always gives me an error saying that a field is required even if I did mention the key:

import requests

url = 'http://text-processing.com/api/sentiment/'
myobj = {'text  ': 'I am feeling reat'}

x = requests.post(url, data = myobj)

print(x.text)

the reponse:

<Response [200]>
Form Validation Errors
text: This field is required.

Does anyone see the problem? because when I do the request using curl it works fine:

curl -d "text=great" http://text-processing.com/api/sentiment/

Response:

{"probability": {"neg": 0.30135019761690551, "neutral": 0.27119050546800266, "pos": 0.69864980238309449}, "label": "pos"}

Upvotes: 0

Views: 1198

Answers (1)

MubtadaNaqvi
MubtadaNaqvi

Reputation: 197

Remove the space after "text", this will work

import requests

url = 'http://text-processing.com/api/sentiment/'
myobj = {'text': 'I am feeling reat'}

x = requests.post(url, data = myobj)

print(x.text)

Upvotes: 1

Related Questions