user2089632
user2089632

Reputation:

SImple http post using python

I have a quick question to call an NLTK Api using python.To find the sentiment of "great"; The API syntax is

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

I need to use a python request to post this and to receive a json object as response.I am trying to use with

resp = requests.post(url, data=values, allow_redirects=True)

if url is http://text-processing.com/api/sentiment/ how must text parameter to be passed?

Upvotes: 0

Views: 172

Answers (1)

shaktimaan
shaktimaan

Reputation: 12092

Modifying the guide from the requests documentation, to suit your requirement, this is what you do:

>>> import json
>>> url = 'http://text-processing.com/api/sentiment/'
>>> payload = {'text': 'great'}

>>> r = requests.post(url, data=json.dumps(payload))

Upvotes: 1

Related Questions