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)
兩個表都有在其中的至少一種元素。區別在於第一個返回結果,而第二個不是。任何幫助將不勝感激。乾杯!