Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send request to endpoint with Boto

I am trying to list items in a S3 container with the following code.

import boto.s3
from boto.s3.connection import OrdinaryCallingFormat

conn = boto.connect_s3(calling_format=OrdinaryCallingFormat())
mybucket = conn.get_bucket('Container001')

for key in mybucket.list():
    print key.name.encode('utf-8')

Then I get the following error.

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    mybucket = conn.get_bucket('Container001')
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 370, in get_bucket
bucket.get_all_keys(headers, maxkeys=0)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 358, in get_all_keys
'', headers, **params)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 325, in _get_all
response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 301 Moved Permanently
<?xml version="1.0" encoding="UTF-8"?>
PermanentRedirectThe bucket you are attempting to access  must be addressed using the  specified endpoint. Please send all future requests to this endpoint.99EBDB9DE3B6E3AF
Container001
<HostId>5El9MLfgHZmZ1UNw8tjUDAl+XltYelHu6d/JUNQsG3OaM70LFlpRchEJi9oepeMy</HostId><Endpoint>Container001.s3.amazonaws.com</Endpoint></Error>

I tried to search for how to send requests to the specified end point, but couldn't find useful information.

How do I avoid this error?

like image 431
user3394040 Avatar asked Mar 07 '14 19:03

user3394040


1 Answers

As @garnaat mentioned and @Rico answered in another question connect_to_region works with OrdinaryCallingFormat:

conn = boto.s3.connect_to_region(
   region_name = '<your region>',
   aws_access_key_id = '<access key>',
   aws_secret_access_key = '<secret key>',
   calling_format = boto.s3.connection.OrdinaryCallingFormat()
   )
bucket = conn.get_bucket('<bucket name>')
like image 79
Norbert Sebők Avatar answered Oct 02 '22 01:10

Norbert Sebők