Error was retrieving data from S3 using boto for python
Question: I'm trying to get data from Amazon S3 using boto for python.

    
    
    from boto.s3.connection import S3Connection
    
    AWS_KEY = 'MY_KEY'
    AWS_SECRET = 'MY_SECRET'
    aws_connection = S3Connection(AWS_KEY, AWS_SECRET)
    bucket = aws_connection.get_bucket('s3://mybucket.buckets.com/')
    for file_key in bucket.list():
        print file_key.name
    

I'm passing a valid Key, secret_key and Bucketname.

When I try executing the above code I'm getting the following error -

    
    
    Traceback (most recent call last):
      File "MyPython_Script.py", line 7, in <module>
        bucket = aws_connection.get_bucket('s3://mybucket.buckets.com/')
      File "/usr/local/lib/python2.7/site-packages/boto/s3/connection.py", line 506, in get_bucket
        return self.head_bucket(bucket_name, headers=headers)
      File "/usr/local/lib/python2.7/site-packages/boto/s3/connection.py", line 525, in head_bucket
        response = self.make_request('HEAD', bucket_name, headers=headers)
      File "/usr/local/lib/python2.7/site-packages/boto/s3/connection.py", line 668, in make_request
        retry_handler=retry_handler
      File "/usr/local/lib/python2.7/site-packages/boto/connection.py", line 1071, in make_request
        retry_handler=retry_handler)
      File "/usr/local/lib/python2.7/site-packages/boto/connection.py", line 1030, in _mexe
        raise ex
    socket.gaierror: [Errno 8] nodename nor servname provided, or not known
    

Any idea how to overcome this error ? Is my format used to pass the bucket
name correct ?


Answer: You just need to pass the name of you bucket, not a seamless URL (note that s3
endpoint would be <http://s3-aws-region.amazonaws.com/bucket>)

If you're using boto2

    
    
    from boto.s3.connection import S3Connection
    
    AWS_KEY = 'MY_KEY'
    AWS_SECRET = 'MY_SECRET'
    aws_connection = S3Connection(AWS_KEY, AWS_SECRET)
    bucket = aws_connection.get_bucket('bucket_name', validate=False)
    for file_key in bucket.list():
        print file_key.name
    

If you're using boto3

    
    
    import boto3
    
    s3 = boto3.resource('s3')
    bucket = s3.Bucket('name')
    

