0

只是试图在 python 中向自然语言 API 发送一个简单的请求,但我不明白为什么它不起作用;代码:

import requests
import json

apikey = *Blanked*

URL = "https://language.googleapis.com/v1/documents:analyzeSentiment?key=" + apikey

content = {
    "type": "PLAIN_TEXT",
    "content": "Inception is one of the shittest movies of all time. I think no-one should watch it."
}

request_raw = {
    "document": content,
    "encodingType": "UTF8"
}

json_package = json.dumps(request_raw)

r = requests.post(url = URL, params = json_package)

api_response = r.json()

print(api_response)

我得到的错误:

{'error': {'code': 400, 'message': 'Invalid JSON payload received. Unknown name "{"document": {"type": "PLAIN_TEXT", "content": "Inception is one of the shittest movies of all time. I think no-one should watch it."}, "encodingType": "UTF8"}": Cannot bind query parameter. Field \'{"document": {"type": "PLAIN_TEXT", "content": "Inception is one of the shittest movies of all time\' could not be found in request message.', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'description': 'Invalid JSON payload received. Unknown name "{"document": {"type": "PLAIN_TEXT", "content": "Inception is one of the shittest movies of all time. I think no-one should watch it."}, "encodingType": "UTF8"}": Cannot bind query parameter. Field \'{"document": {"type": "PLAIN_TEXT", "content": "Inception is one of the shittest movies of all time\' could not be found in request message.'}]}]}}
4

0 回答 0