Python 2.7 为什么使用';未找到请求的资源';?
我已经仔细检查了dynamodb表中是否存在该项Python 2.7 为什么使用';未找到请求的资源';?,python-2.7,amazon-dynamodb,boto,Python 2.7,Amazon Dynamodb,Boto,我已经仔细检查了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_
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()
def get_table():
return table.Table(table, get_db_conn())
但是,我得到了以下例外:
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'}
文件“scripts/support/find_doc.py”,第31行,在
main()
文件“scripts/support/find_doc.py”,第33行,主目录
doc=tbl.get_项目(id='4d7a73b6-2121-46c8-8fc2-54cd4ceb2a30')
文件“/Users/antkong/project ve/lib/python2.7/site packages/boto/dynamodb2/table.py”,第504行,在get_项中
一致的,一致的
文件“/Users/antkong/project ve/lib/python2.7/site packages/boto/dynamodb2/layer1.py”,第1065行,在get_项中
body=json.dumps(参数))
文件“/Users/antkong/project ve/lib/python2.7/site packages/boto/dynamodb2/layer1.py”,第2731行,在make_请求中
retry\u handler=self.\u retry\u handler)
文件“/Users/antkong/project ve/lib/python2.7/site packages/boto/connection.py”,第953行,在
状态=重试\u处理程序(响应、i、下一个\u睡眠)
文件“/Users/antkong/project ve/lib/python2.7/site packages/boto/dynamodb2/layer1.py”,第2774行,在“重试”处理程序中
(数据)
boto.exception.JSONResponseError:JSONResponseError:400错误请求
{u'message':u'Requested resource not foundexception',u'uu type':u'com.amazonaws.dynamodb.v20120810#resource notfoundexception'}
为什么我会收到此错误消息
我使用的是
boto
version 2.34此代码中存在问题:
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()
def get_table():
return table.Table(table, get_db_conn())
应该是
def get_table():
return table.Table(table, connection=get_db_conn())
注意
连接
命名参数如果您有一个范围键,则必须在get\u项中指定,如下所示:
get_item(timestamp=Decimal('1444232509'), id='HASH_SHA1')
在我的表包中,我有一个索引(id)和一个范围键(时间戳)。我收到这个错误,因为我连接到了错误的区域 要检查您的表区域,请转到表的overview选项卡并向下滚动到Amazon资源名称(ARN)字段
我的ARN以ARN:aws:dynamodb:us-east-2:开头。这里的“us-east-2”是启动boto3客户端时需要经过的区域。您在AWS控制台中看到的是哪个区域?us-west-2。请参见代码中的变量
区域