我正在使用boto
Python 中的库用于连接到 DynamoDB。以下代码对我来说效果很好:
import boto
key = 'abc'
secret = '123'
con = boto.connect_dynamodb(key,secret)
table = con.get_table('Table Name')
-- rest of code --
当我尝试连接到特定区域时,我可以很好地连接,但让表正常工作会引发错误:
import boto
from boto.ec2.connection import EC2Connection
key = 'abc'
secret = '123'
regions = EC2Connection(key,secret).get_all_regions() # some filtering after this line to remove unwanted entries
for r in regions:
con = boto.connect_dynamodb(key,secret,region=r)
table = con.get_table('Table Name') # throws the error below
-- rest of code --
使用上面的第二个代码块,我得到ValueError: No JSON object could be decoded
。呼唤con.list_tables()
显示我在第一个代码块中查找的表,但当我在第二个代码块中尝试它时抛出相同的错误。谁能帮我吗?
经过一番尝试,我发现更改代码以这种方式连接是有效的:
import boto
from boto.ec2.connection import EC2Connection
from boto.dynamodb import connect_to_region
key = 'abc'
secret = '123'
regions = EC2Connection(key,secret).get_all_regions()
for r in regions:
con = connect_to_region(aws_access_key_id=key,aws_secret_access_key=secret,region_name=r.name)
table = con.get_table('Table Name') # no problem
-- rest of code --
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)