0
我使用扫描来查询两个发电机数据库表,将它们存储在列表中,然后将它们返回(所有这些都在Flask应用程序中)。很简单,没有什么幻想。DynamoDB scan()ResultSet没有属性键
的问题是,对于一个它的工作原理没有问题,但对于其他的我得到这个:
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)
两个表都有在其中的至少一种元素。区别在于第一个返回结果,而第二个不是。任何帮助将不胜感激。干杯!