Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
JSON负载、AWS Lambda(Python)、API网关_Python_Amazon Web Services_Api_Aws Lambda_Api Gateway - Fatal编程技术网

JSON负载、AWS Lambda(Python)、API网关

JSON负载、AWS Lambda(Python)、API网关,python,amazon-web-services,api,aws-lambda,api-gateway,Python,Amazon Web Services,Api,Aws Lambda,Api Gateway,我通过API网关接收到Lambda函数的有效负载 { "resource": "/onfleet-webhook-production", "path": "/onfleet-webhook-production", "httpMethod": "POST", "headers": { "accept": "applic

我通过API网关接收到Lambda函数的有效负载

{
"resource": "/onfleet-webhook-production",
"path": "/onfleet-webhook-production",
"httpMethod": "POST",
"headers": {
    "accept": "application/json",
    "content-type": "application/json",
    "Host": "fje4zhwf83.execute1-api.us-east-1.amazonaws.com",
    "X-Amzn-Trace-Id": "Root=1-60884247-298cc6854b722b00668b0553",
    "X-Forwarded-For": "54.84.188.171",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https",
    "X-Onfleet-Signature": "539370210b482cbb4f7d728ecb33a690c89ff70dc574475000788d0fedfdd25471a45e909f42a951d8ccbb53c22ab0a548f3c7a7fa965b697ab13544c92ff08b"
},
"multiValueHeaders": {
    "accept": ["application/json"],
    "content-type": ["application/json"],
    "Host": ["fje4zhwf83.execute-api.us-east-1.amazonaws.com"],
    "X-Amzn-Trace-Id": ["Root=1-60884247-298cc6854b722b00668b0553"],
    "X-Forwarded-For": ["54.84.188.171"],
    "X-Forwarded-Port": ["443"],
    "X-Forwarded-Proto": ["https"],
    "X-Onfleet-Signature": ["539370210b482cbb4f7d728ecb33a690c89ff70dc574475000788d0fedfdd25471a45e909f42a951d8ccbb53c22ab0a548f3c7a7fa965b697ab13544c92ff08b"]
},
"queryStringParameters": null,
"multiValueQueryStringParameters": null,
"pathParameters": null,
"stageVariables": null,
"requestContext": {
    "resourceId": "0xos2v",
    "resourcePath": "/onfleet-webhook-production",
    "httpMethod": "POST",
    "extendedRequestId": "ec9LLEw0oAMFkwA=",
    "requestTime": "27/Apr/2021:16:56:39 +0000",
    "path": "/default/onfleet-webhook-production",
    "accountId": "406135884221",
    "protocol": "HTTP/1.1",
    "stage": "default",
    "domainPrefix": "fje4zhwf83",
    "requestTimeEpoch": 1619542599421,
    "requestId": "9485a44a-44f7-436c-9e98-0cb7d9034513",
    "identity": {
        "cognitoIdentityPoolId": null,
        "accountId": null,
        "cognitoIdentityId": null,
        "caller": null,
        "sourceIp": "54.84.188.171",
        "principalOrgId": null,
        "accessKey": null,
        "cognitoAuthenticationType": null,
        "cognitoAuthenticationProvider": null,
        "userArn": null,
        "userAgent": null,
        "user": null
    },
    "domainName": "fje4zhwf83.execut1e-api.us-east-1.amazonaws.com",
    "apiId": "fje4zhwf83"
},
"body": "{\"taskId\":\"f7XbmRxXvfntB086PseFXpZ9\",\"actionContext\":{\"type\":\"WORKER\",\"id\":\"C~s63JVCJTtD12J4BCY2Y4cN\"},\"triggerId\":0,\"triggerName\":\"taskStarted\",\"workerId\":\"C~s63JVCJTtD12J4BCY2Y4cN\",\"adminId\":null,\"data\":{\"task\":{\"id\":\"f7XbmRxXvfntB086PseFXpZ9\",\"timeCreated\":1619535291000,\"timeLastModified\":1619535394486,\"organization\":\"hFz5MmFqcMoMwjYmvvPbBo5U\",\"shortId\":\"4334535c\",\"trackingURL\":\"https://onf.lt/4334535c0c\",\"worker\":\"C~s63JVCJTtD12J4BCY2Y4cN\",\"merchant\":\"hFz5MmFqcMoMwjYmvvPbBo5U\",\"executor\":\"hFz5MmFqcMoMwjYmvvPbBo5U\",\"creator\":\"YG5INuyrKz4dggsW7Vo0q*Nv\",\"dependencies\":[],\"state\":2,\"completeAfter\":null,\"completeBefore\":null,\"pickupTask\":false,\"notes\":\"\",\"completionDetails\":{\"failureNotes\":\"\",\"failureReason\":\"NONE\",\"events\":[],\"actions\":[],\"time\":null,\"firstLocation\":[],\"lastLocation\":[],\"unavailableAttachments\":[]},\"feedback\":[],\"metadata\":[],\"overrides\":{},\"quantity\":0,\"serviceTime\":0,\"identity\":{\"failedScanCount\":0,\"checksum\":null},\"appearance\":{\"triangleColor\":null},\"container\":{\"type\":\"WORKER\",\"worker\":\"C~s63JVCJTtD12J4BCY2Y4cN\"},\"trackingViewed\":false,\"estimatedCompletionTime\":null,\"estimatedArrivalTime\":null,\"destination\":{\"id\":\"yIDUKM65Ck8bwNEP8z4W42Ea\",\"timeCreated\":1619535291000,\"timeLastModified\":1619535291451,\"location\":[-71.25429253636486,42.244868727926736],\"address\":{\"apartment\":\"\",\"state\":\"Massachusetts\",\"postalCode\":\"02030\",\"number\":\"35\",\"street\":\"Strawberry Hill Street\",\"city\":\"Dover\",\"country\":\"United States\"},\"notes\":\"\",\"metadata\":[],\"googlePlaceId\":null,\"warnings\":[]},\"recipients\":[{\"id\":\"5DoYN3*udPr8eUuEELGPq6yk\",\"timeCreated\":1571336170000,\"timeLastModified\":1619535291465,\"name\":\"s Test\",\"phone\":\"+16378343616\",\"notes\":\"Testing Email\",\"organization\":\"hFz5MmFqcMoMwjYmvvPbBo5U\",\"skipSMSNotifications\":false,\"metadata\":[]}]}},\"time\":1619535394615}",
"isBase64Encoded": false
}

我可以访问这个JSON中的值; 前<代码>数据=事件。获取('path')

但是,我无法访问“body”中的任何变量

`event.get('body')` doesn't seem to work at all
如何访问主体中的值,如“taskId”、“timeCreated”等


我尝试过不同的方法,比如json.load(event)。但它们最终都会得到相同的结果。

您的
正文是一个字符串。您必须使用解析它以获得有效的python映射:

import ast

body = ast.literal_eval(event['body'])
然后您应该能够使用
body
作为常规地图

备选方案

import json

body = json.loads("{}".format(event['body']))

感谢您的回复。不幸的是,我现在收到了这个错误;ValueError:格式错误的节点或字符串:@AAA是什么生成了正文?是AWS服务还是某个第三方应用程序?它是一个名为OnFleet的第三方工具,生成有效负载,并在AWS(API网关)调用我们的web钩子,然后调用我们的Lambda(Python)功能。@AAA我提供了备选方案。你能检查一下吗?这很有效!!!非常感谢!!!