尝试从s3读取json时不断收到错误消息

我的lambda函数中不断出现此错误:

{"errorMessage": "module initialization error"}

当我尝试将以下包含json数据的字符串转换为python中的json字典对象时,就会发生这种情况。

"{\n\"main\": {\n  \"PART_NAME\": \"Genuine Cardboard Honda Wing\",\n  \"BRAND\": \"Honda\",\n  \"MJR_CAT\": \"Aero\",\n  \"CAT\": \"Rear Wing\",\n  \"SUB_CAT\": \"NA\",\n  \"Power_Increase\": \"0\"\n},\n\"forza\":\n{\n  \"power\": \"[0,True]\",\n  \"Torque\": \"[0,\n  \"Traction\": \"[50,\n  \"Handling\": \"[100,\n  \"Breaking\": \"[40,True]\"\n},\n\"custom\": {\n\"length\": 120,\n\"car max height[m]\": 2,\n\"RICER RANK\": -10\n\n}\n"

这是我的代码来复制此错误:

client = boto3.client('s3')
result = client.get_object(Bucket=BUCKET,Key=FILE_TO_READ) 
text = result['Body'].read().decode('utf-8')
text = json.load(text)
print(text) 

在没有print(text)的情况下会在上方生成该字符串。

谢谢:)

如果您有兴趣,这里是完整的lambda函数(尽管未评论)。

import json
import boto3
print('got this far')
BUCKET = '******'
FILE_TO_READ = 'example_honda_wing.json'
client = boto3.client('s3')
result = client.get_object(Bucket=BUCKET,Key=FILE_TO_READ) 
text = result['Body'].read().decode('utf-8')
#text = str(text).replace("\n","")
#text = text.replace('\"',' ')

#text = json.load(text)
print(text) # Use your desired JSON Key for your value 

def lambda_handler(event,context):
    # TODO implement
    return text
laolvye 回答:尝试从s3读取json时不断收到错误消息

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167349.html

大家都在问