4

I am trying to query this API from within Python. It seems to respond with 400 code. Can some one tell me how should this API be queried?

This API is documented at http://text-processing.com/docs/phrases.html

import requests
r = requests.post('http://text-processing.com/api/phrases/',
                  data= {'text':'This is California.'})

I guess I am misunderstanding the way that data should be posted here.

2
  • I get a 200 response for that exact code. Commented Jul 15, 2015 at 21:10
  • amazing... it was not working earlier for me. Now it works fine!! I am so doomed! Commented Jul 15, 2015 at 21:57

1 Answer 1

6

You are doing it exactly right; sending a POST request with a text parameter gives me a 200 response with JSON body:

>>> import requests
>>> url = 'http://text-processing.com/api/phrases/'
>>> params = {'text': 'This is California.'}
>>> r = requests.post(url, data=params)
>>> r
<Response [200]>
>>> r.json()
{u'NP': [u'California', u'This'], u'GPE': [u'California'], u'VP': [u'is'], u'LOCATION': [u'California']}

If you get a 400 response instead you are sending too much data or an empty value:

Errors

A 400 Bad Request response will be returned under the following conditions:

  • no value for text is provided
  • text exceeds 1,000 characters
  • an incorrect language is specified

language can be english, dutch, portuguese or spanish, but defaults to english if you don't include it. If you do include it in your request you can also get a 400 error if you don't set it to one of those 4 supported values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.