Could not parse request body into json: Unrecognized token 'xxx': was expecting ('true', 'false' or

调用 Lambda 函数时你可能遇到以下错误:

==================== INVOCATION ERROR ====================

com.amazonaws.services.lambda.model.InvalidRequestContentException: Could not parse request body into json: Unrecognized token 'first': was expecting 'null', 'true', 'false' or NaN

 at [Source: [[email protected]; line: 1, column: 7] (Service: AWSLambda; Status Code: 400; Error Code: InvalidRequestContentException; Request ID: 946370eb-33cc-11e8-ada5-xxxxxxxxxxx)


这是因为在调用时输入的参数格式不对!

输入的JSON字符串需要添加双引号

Could not parse request body into json: Unrecognized token 'xxx': was expecting ('true', 'false' or

调用成功可以看到以下控制台输出:

Skip uploading function code since no local change is found...

Invoking function...

==================== FUNCTION OUTPUT ====================

"Hello, first lambda!"

==================== FUNCTION LOG OUTPUT ====================

START RequestId: fddbb722-33cc-11e8-8d29-xxxxxxx Version: $LATEST

Input: first lambdaEND RequestId: fddbb722-33cc-11e8-8d29-xxxxxxxxxxx

REPORT RequestId: fddbb722-33cc-11e8-8d29-xxxxxxxxx Duration: 18.62 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 43 MB


2018-07-12更新

有小伙伴使用Python时遇到类似的问题

  • s.headers.update(headers)
    result = s.post(url, data=data)

    python3 使用requests 去POS请求一个接口,结果服务器报错了

错误提示是JSON 解析错误,在post之前需要对字典进行处理吗?

原始的报错信息是这个

JSON parse error: Unrecognized token 'from': was expecting 'null', 'true', 'false' or NaN; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'from': was expecting 'null', 'true', 'false' or NaN

我的回复:

result = s.post(url, data=data)

看看你提交的数据 data,格式是不是有问题

他:

  • {'size': 20, 'catalogueId': '473', 'from': 0}

很正常的一个dic呀

需要把dic转换一下,文档上面却没要求转

我:哪个文档?

Could not parse request body into json: Unrecognized token 'xxx': was expecting ('true', 'false' or

Could not parse request body into json: Unrecognized token 'xxx': was expecting ('true', 'false' or