0

Unirest is not compatible with python3 and that's the library that mashape APIs' use on python projects.

I've decided to use python request library to make a POST request, but I'm getting a 400 HTTP error. Everything looks good to me, but I can't figure out what I'm doing wrong.

url = "https://japerk-text-processing.p.mashape.com/sentiment/"

myHeaders={
  "X-Mashape-Key": mashape_key,
  "Content-Type": "application/x-www-form-urlencoded",
  "Accept": "application/json"
}

myParams={
  "language": "english",
  "text": tweet_text
}

r = requests.post(url, headers=myHeaders, params=myParams)
print(r)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

According to the docs, UNIREST takes the argument:

params - Request Body as an associative array or object

However, requests, per its own documentation, uses params to supply URL query parameters, not the request body.

Try using the data parameter to pass an actual request body instead; see the docs again. You will probably have to keep double-checking parameter names in the two sets of documentation to ensure you're passing the right thing.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • http://docs.python-requests.org/en/master/api/#requests.post requests.post(url, data=None, json=None, **kwargs) **kwargs -- Optional arguments that request takes. http://docs.python-requests.org/en/master/api/#requests.request This function takes in header and params as inputs. I'll try the data as the only input. – avaldez1412 Jan 29 '17 at 20:57
  • @avaldez1412 you will have to pass headers too, if that's where the API key goes. – jonrsharpe Jan 29 '17 at 21:15
  • Thanks, using data instead of params worked and I included headers. – avaldez1412 Jan 29 '17 at 22:06