Http post请求Python失败.(必填字段)



我一直在尝试在这个网站的API上做HTTP post请求:http://text-processing.com/docs/sentiment.html

但它总是给我一个错误,说一个字段是必需的,即使我提到了键:

import requests
url = 'http://text-processing.com/api/sentiment/'
myobj = {'text  ': 'I am feeling reat'}
x = requests.post(url, data = myobj)
print(x.text)

反应:

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

有人看到问题了吗?因为当我使用curl做请求时,它工作得很好:

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

反应:

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

去掉"text"后面的空格,这样就可以了

import requests
url = 'http://text-processing.com/api/sentiment/'
myobj = {'text': 'I am feeling reat'}
x = requests.post(url, data = myobj)
print(x.text)

最新更新