POST request with form data using Python's request
Question: 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.


Answer: 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.

