Python DynamoDB/Boto3-参数表达式属性值的类型无效,类型为NULL
因此,我有一个AWS数据库,它有4个列属性:Python DynamoDB/Boto3-参数表达式属性值的类型无效,类型为NULL,python,amazon-web-services,amazon-dynamodb,boto3,Python,Amazon Web Services,Amazon Dynamodb,Boto3,因此,我有一个AWS数据库,它有4个列属性: id(主分区键) 位置(纬度坐标为字符串) 位置2(作为字符串的经度坐标) 用户位置(用户位置为字符串,例如“美国纽约” 只有数据库中的某些项填写了location和location2,我想用空的location和location2(而不是不存在的)项来填充这些项 我通过扫描数据库,获取用户位置,并将其转换为纬度和经度坐标,等等 然后,如果存在location2,我会检查ConditionExpression(我犯了一个错误,在某些项目中有locat
location
和location2
,我想用空的location
和location2
(而不是不存在的)项来填充这些项
我通过扫描数据库,获取用户位置
,并将其转换为纬度和经度坐标,等等
然后,如果存在location2
,我会检查ConditionExpression
(我犯了一个错误,在某些项目中有location
,但没有location2
)我通过查看转换后的坐标是否为None
/NULL
类型来检查转换后的坐标是否正确。如果满足条件,则它应该更新,从而填充数据库中的空槽
以下是我的功能:
def scan()
response = client.scan(
TableName=TABLE_NAME,
)
geolocator = GoogleV3()
sleep(1.1)
non_value = None
for i in response['Items']:
idNr = i['id']['N']
try:
userLocation = i['user location']['S']
coordinates = geolocator.geocode(userLocation, timeout=10)
sleep(1.1)
latitude = coordinates.latitude
sleep(1.1)
longitude = coordinates.longitude
sleep(1.1)
print "User Location succesfully made into coordinates"
if latitude and longitude:
print latitude, longitude
response = client.update_item(
Key={'id': {'N': str(idNr)}},
TableName=TABLE_NAME,
ExpressionAttributeNames={"#c":"location"},
UpdateExpression='SET #c = :lati, location2 = :longi, #n = :null',
ConditionExpression="attribute_not_exists(location2) OR attribute_type(userLoca, #n) OR attribute_type(lati, #n) OR attribute_type(longi, #n)",
ExpressionAttributeValues={
':lati': {'S': str(latitude)},
':longi': {'S': str(longitude)},
':userLoca': {'S': userLocation},
':null': {'NULL': non_value}
},
ReturnValues="UPDATED_NEW"
)
except ClientError as e:
if e.response['Error']['Code'] == "ConditionalCheckFailedException":
print(e.response['Error']['Message'])
else:
raise
因此,根据文档,我应该能够使用函数属性\u type(path,type)
,如下所述:
但我一直得到:
参数表达式属性值的类型无效:null.null,值:无,类型:,有效类型:
文档清楚地说明我可以在函数中使用NULL
作为类型,我还根据规范正确指定了ExpressionAttributeValues
!不知道哪里出错了
求你了,斯塔克之神,你是我唯一的希望。听起来很奇怪,空值不是零,它必须是真的(有趣的是,它不能是假的,试过了),因为dynamodb中的空类型只接受这个值 因此,请将代码更改为:
non_value=True
它应该会起作用
基于听起来很奇怪的原因,NULL值不是None,它必须是true(有趣的是,它不可能是false,试试看),因为dynamodb中的NULL类型只接受这个值 因此,请将代码更改为:
non_value=True
它应该会起作用
基于