首页 > 解决方案 > 如何将布尔值(由函数返回)传递给 boto3 put_item() 函数

问题描述

我有一个功能,

def _get_package_(sandboxId):

    for i in response_tci_sandboxes['Items']:
            if sandboxId == i['id']['S']:
                    if i.get('sandboxType') == 'operational':
                            return True  ## Please note that true(lowercase) is not allowed
                    else:
                            return False

    return 1

现在的问题是,当我将上述函数返回的值传递给 put_item 函数时,它会抛出错误,因为它期望布尔值是小写的,即 true 或 false。

我试着用这样的东西。

 str(_get_package_(sandboxId)).lower

但是 put_item 将它作为一个字符串,并且请求被拒绝,因为数据类型是 BOOL。

标签: python-3.xamazon-dynamodbboto3

解决方案


推荐阅读