我是 Boto 的新手,我正在尝试使用它将 Python 字典插入 Amazon DynamoDB。我一定遗漏了一些东西,因为“dynamizer”(编码器)似乎不支持 None 值。这是一个问题,因为源数据中有大量的空值。我可以遍历每一行并删除值为 None 的所有键/值项,但不知何故,我觉得像 Boto 这样复杂的包应该为我处理。我只是想像这样插入一行:
conn = DynamoDBConnection(region=RegionInfo(endpoint="dynamodb.us-west-2.amazonaws.com"))
dest = Table('d_company', connection=conn)
data = {"company_id":99999, "company_name":None}
dest.put_item(data)
...这给了我错误:
Error
Traceback (most recent call last):
File "TestDynamoDB.py", line 37, in testPutIntoDynamoDB
dest.put_item(data)
File "C:\Python27\lib\site-packages\boto\dynamodb2\table.py", line 452, in put_item
return item.save(overwrite=overwrite)
File "C:\Python27\lib\site-packages\boto\dynamodb2\items.py", line 362, in save
final_data = self.prepare_full()
File "C:\Python27\lib\site-packages\boto\dynamodb2\items.py", line 265, in prepare_full
final_data[key] = self._dynamizer.encode(value)
File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 228, in encode
dynamodb_type = self._get_dynamodb_type(attr)
File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 220, in _get_dynamodb_type
return get_dynamodb_type(attr)
File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 110, in get_dynamodb_type
raise TypeError(msg)
TypeError: Unsupported type "<type 'NoneType'>" for value "None"
我究竟做错了什么?