Reputation: 521
I want to use pure http requests to get the result from google cloud natural language api, but their document does not specify the parameter names.
Here is my python code:
import requests
url = "https://language.googleapis.com/v1beta1/documents:analyzeEntities"
d = {"document": {"content": "some text here", "type": "PLAIN_TEXT"}}
para = {"key": "my api key"}
r = requests.post(url, params=para, data=d)
Here is the error message:
{u'error': {u'status': u'INVALID_ARGUMENT', u'message': u'Invalid JSON payload received. Unknown name "document": Cannot bind query parameter. \'document\' is a message type. Parameters can only be bound to primitive types.', u'code': 400, u'details': [{u'fieldViolations': [{u'description': u'Invalid JSON payload received. Unknown name "document": Cannot bind query parameter. \'document\' is a message type. Parameters can only be bound to primitive types.'}], u'@type': u'type.googleapis.com/google.rpc.BadRequest'}]}}
how should I create the http request without using their python library?
Upvotes: 10
Views: 2635
Reputation: 521
ok, I figured it out. I need to pass JSON-Encoded POST/PATCH data, so the request should be r = requests.post(url, params=para, json=d)
Upvotes: 14