我已经仔细检查过该项目是否存在于dynamodb表中。id
是默认的哈希键。
我想通过使用main
以下代码中的函数来检索内容:
import boto.dynamodb2
from boto.dynamodb2 import table
table='doc'
region='us-west-2'
aws_access_key_id='YYY'
aws_secret_access_key='XXX'
def get_db_conn():
return boto.dynamodb2.connect_to_region(
region,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
def get_table():
return table.Table(table, get_db_conn())
def main():
tbl = get_table()
doc = tbl.get_item(id='4d7a73b6-2121-46c8-8fc2-54cd4ceb2a30')
print doc.keys()
但是我得到了这个异常:
File "scripts/support/find_doc.py", line 31, in <module>
main()
File "scripts/support/find_doc.py", line 33, in main
doc = tbl.get_item(id='4d7a73b6-2121-46c8-8fc2-54cd4ceb2a30')
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/table.py", line 504, in get_item
consistent_read=consistent
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 1065, in get_item
body=json.dumps(params))
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 2731, in make_request
retry_handler=self._retry_handler)
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/connection.py", line 953, in _mexe
status = retry_handler(response, i, next_sleep)
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 2774, in _retry_handler
data)
boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request
{u'message': u'Requested resource not found', u'__type': u'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException'}
为什么我收到此错误消息?
我正在使用boto
2.34版
问题出在以下代码中:
def get_table():
return table.Table(table, get_db_conn())
它应该是
def get_table():
return table.Table(table, connection=get_db_conn())
注意connection
命名参数
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句