3

I'm using the boto library in Python to connect to DynamoDB. The following code has been working for me just fine:

import boto
key = 'abc'

secret = '123'
con = boto.connect_dynamodb(key,secret)
table = con.get_table('Table Name')
-- rest of code --

When I try to connect to a specific region, I can connect just fine, but getting the table to work on is throwing an error:

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 --

Using the second block of code above, I get a ValueError: No JSON object could be decoded. Calling con.list_tables() shows the table I'm looking for in the first code block, but throws the same error when I try it in the second code block. Can anyone help me out?

4

1 に答える 1

5

After playing around, I found out that changing the code to connect in this fashion works:

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 --
于 2012-06-19T14:06:35.107 に答える