Amazon web services DynamoDB scan()结果集没有属性键
我正在使用scan查询两个dynamo db表,以获取其中的所有项目,将它们存储在一个列表中,然后返回它们(所有这些都在一个Flask应用程序中)。很简单,没什么特别的 问题是,对于一个,它可以正常工作,但对于另一个,我得到以下结论:Amazon web services DynamoDB scan()结果集没有属性键,amazon-web-services,flask,amazon-dynamodb,boto,Amazon Web Services,Flask,Amazon Dynamodb,Boto,我正在使用scan查询两个dynamo db表,以获取其中的所有项目,将它们存储在一个列表中,然后返回它们(所有这些都在一个Flask应用程序中)。很简单,没什么特别的 问题是,对于一个,它可以正常工作,但对于另一个,我得到以下结论: for entry in squads_info: File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/layer2.py", line 125, in __iter__ response = se
for entry in squads_info:
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/layer2.py", line 125, in __iter__
response = self.response
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/layer2.py", line 92, in response
return self.next_response() if self._response is None else self._response
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/layer2.py", line 104, in next_response
self._response = self.callable(**self.kwargs)
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/layer1.py", line 577, in scan
return self.make_request('Scan', json_input, object_hook=object_hook)
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/layer1.py", line 127, in make_request
return json.loads(response_body, object_hook=object_hook)
File "/usr/local/lib/python2.7/json/__init__.py", line 351, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/usr/local/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/types.py", line 347, in decode
return decoder(attr[dynamodb_type])
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/types.py", line 377, in _decode_l
return [self.decode(i) for i in attr]
File "/usr/local/lib/python2.7/site-packages/boto/dynamodb/types.py", line 338, in decode
dynamodb_type = list(attr.keys())[0]
AttributeError: 'unicode' object has no attribute 'keys'
以下是第一次扫描的代码:
def get_browsers():
# the database table instance that can be scanned
browsers = get_table_connection('Browser')
# a list of the environments in the table
browser_list = []
# getting the full list of environments in the table
results = browsers.scan()
# add a dictionary entry for each result we get
for result in results:
entry = {
"name": result['name'],
"versions": result['versions']
}
browser_list.append(entry)
# return the env_list
return jsonify(result=browser_list)
这是失败的扫描代码
@logger_app.route("/squad-information", methods=['GET'])
def get_squad_info():
# get connection to db
squads = get_table_connection('Squad')
# we need to return all the information we have stored in this table, so a scan should do
squads_info = squads.scan()
# start building up the response
# response is an array of dictionaries
response = []
for entry in squads_info:
response_entry = {
"name": entry['name'],
"squad_id": entry['squad_id'],
"test_suites": entry['test_suites']
}
response.append(response_entry)
return jsonify(squads=response)
两个表中至少有一个元素。区别在于第一个返回结果,而第二个不返回。任何帮助都将不胜感激。干杯 问题是使用DynamoDB版本1(即不推荐使用的版本)。一旦我切换到连接新版本的表,并用适当的方法执行扫描,它就工作了 希望这能帮助其他被跨版本错配弄糊涂的受苦灵魂