我想使用纯http请求从google cloud自然语言api获取结果,但是他们的文档没有指定参数名称。
这是我的python代码:
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)
以下是错误消息:
{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'}]}}
如何在不使用python库的情况下创建http请求?
答案 0 :(得分:5)
r = requests.post(url, params=para, json=d)