0

我已经尝试将uuid转换为下面代码中的字符串,并且总是出现错误。无论我是否不声明STR()分开uuid.uuid4() 参见下面的代码:运行AWS Lambda时将str()错误(将uuid转换为字符串)w/Dynamo DB

from __future__ import print_function 
    from decimal import * 
    import boto3 
    import json 
    from locale import str 
    import uuid 

    def my_handler(event, context): 
     description = event['description'] 
     spot_id = uuid.uuid4() #Unique identifier for spot 
     dynamodb = boto3.client('dynamodb') 
     tablesinfo = "sinfo" 
     dynamodb.put_item(
     TableName = tablesinfo, Item = { 
      'spot_id':{'S' : str(spot_id)}, 
      'description': {'S' : description 
      } 
     ) 
     return {'spot_id' : spot_id} 

这些都是错误我收到:

{ 
    "stackTrace": [ 
    [ 
     "/var/task/Create_Spot_Test.py", 
     15, 
     "my_handler", 
     "'spot_id':{'S' : str(spot_id)}," 
    ], 
    [ 
     "/usr/lib64/python2.7/locale.py", 
     303, 
     "str", 
     "return format(\"%.12g\", val)" 
    ], 
    [ 
     "/usr/lib64/python2.7/locale.py", 
     196, 
     "format", 
     "return _format(percent, value, grouping, monetary, *additional)" 
    ], 
    [ 
     "/usr/lib64/python2.7/locale.py", 
     202, 
     "_format", 
     "formatted = percent % value" 
    ] 
    ], 
    "errorType": "TypeError", 
    "errorMessage": "float argument required, not UUID" 
} 

回答

1

from locale import str不需要(被进口对以前的错误)

你也必须首先声明uuid = uuid.uuid4()作为一个变量,然后声明另一个变量将其转换为字符串spot_id = str(uuid),而不是运行str()在线。

相关问题