2016-10-13 2 views
2

순수한 http 요청을 사용하여 Google Cloud 자연 언어 API에서 결과를 가져오고 싶지만 해당 문서에서 매개 변수 이름을 지정하지 않았습니다. {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'}]}} Google Cloud 자연 언어 API 매개 변수

가 어떻게 자신의 파이썬 라이브러리를 사용하지 않고 HTTP 요청을 만들어야합니다 :

여기
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) 

오류 메시지입니다 : 여기

내 파이썬 코드?

답변

3

괜찮 았어. JSON 인코딩 된 POST/PATCH 데이터를 전달해야하므로 요청은 r = requests.post(url, params=para, json=d)

이어야합니다.