Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x API网关-Lambda代理-Python内部服务器错误_Python 3.x_Aws Lambda - Fatal编程技术网

Python 3.x API网关-Lambda代理-Python内部服务器错误

Python 3.x API网关-Lambda代理-Python内部服务器错误,python-3.x,aws-lambda,Python 3.x,Aws Lambda,我在Python3.7中解析来自事件的输入数据时遇到问题 def lambda_handler(event, context): image = event['image'] siteid = int(event['siteid']) camid = int(event['camid']) 错误: Lambda execution failed with status 200 due to customer function error: 'image'. 方法请求模型: { "$

我在Python3.7中解析来自事件的输入数据时遇到问题

def lambda_handler(event, context):
 image = event['image']
 siteid = int(event['siteid'])
 camid = int(event['camid'])
错误:

Lambda execution failed with status 200 due to customer function error: 'image'.
方法请求模型:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "UploadModel",
  "type": "object",
  "properties": {
    "image": { "type": "string" },
    "siteid": { "type": "string" },
    "camid": { "type": "string" }
    }
}
使用Lambda代理集成:打开

它可以通过简单的输入阵列直接从lambda控制台正常工作:

{
    "image": "xxxx"
    "siteid": 2,
    "camid": 1
}
响应函数:

def response(message, status_code):
    return {
        "statusCode": str(status_code),
        "body": json.dumps(message),
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": '*'
            },
        }

您为
事件
对象假定了错误的形状

使用Lambda代理集成时,
事件
采用以下形状

{
    "resource": "Resource path",
    "path": "Path parameter",
    "httpMethod": "Incoming request's method name"
    "headers": {String containing incoming request headers}
    "multiValueHeaders": {List of strings containing incoming request headers}
    "queryStringParameters": {query string parameters }
    "multiValueQueryStringParameters": {List of query string parameters}
    "pathParameters":  {path parameters}
    "stageVariables": {Applicable stage variables}
    "requestContext": {Request context, including authorizer-returned key-value pairs}
    "body": "A JSON string of the request payload."
    "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"
}
参考:

您的请求模型仅适用于
事件
正文

为了说明这一点,请尝试使用此处理程序返回
事件作为响应:

def lambda_handler(event, context):
    return {
        "statusCode": str(status_code),
        "body": json.dumps(message),
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": '*'
            },
        }

我已经添加了这段代码:data=json.loads(json.dumps(event['body']),然后通过以下方式获取值:image=data['image'],但随后我得到了以下错误:Lambda执行失败,状态为200,原因是客户函数错误:字符串索引必须是整数。请尝试
data=json.loads(event['body'])
,因为event['body']是字符串。