Giter VIP home page Giter VIP logo

Comments (5)

danielgtaylor avatar danielgtaylor commented on September 18, 2024

@tianx2 it looks like you probably need to pass the region name when creating your client or resource:

>>> import boto3
>>> s3 = boto3.resource('s3', region_name='us-west-2')
>>> bucket = s3.create_bucket(Bucket='boto3.region',
                              CreateBucketConfiguration={'LocationConstraint': 'us-west-2'})
>>> bucket.Object('hello.txt').put(Body='hello')
...
>>> bucket.Object('hello.txt').last_modified
datetime.datetime(2015, 4, 2, 20, 55, 17, tzinfo=tzutc())

You can also determine the bucket location programmatically:

>>> s3.meta.client.get_bucket_location(Bucket='boto3.region')
{'LocationConstraint': 'us-west-2',
 'ResponseMetadata': {'RequestId': 'abc123',
  'HostId': '12345',
  'HTTPStatusCode': 200}}

This is a limitation of the way that S3 works, but with the above code you can work around it to support any bucket in any region.

Please let me know if you have any other questions.

from boto3.

tianx2 avatar tianx2 commented on September 18, 2024

So my use case was that i was trying to grab the tags for the bucket. Here is some sample code:

import boto3

try:
    s3 = boto3.resource("s3", region_name="us-east-1")
    name = "my.bucket.random"
    dotted_bucket = s3.Bucket(name)
    print dotted_bucket.Tagging().tag_set
except Exception as e:
    print e.message

Event with your suggestion, I still get the error.
Steps:

  1. Create a bucket with dots (".") in the name.
  2. Replace name = "my.bucket.random" in sample code with the created bucket name
  3. Run sample code.

Result:

An error occurred (PermanentRedirect) when calling the GetBucketTagging operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

I did a test on Python 2.7.8 as well. I get the error there too, so I don't think it's related to the SSL issue.

from boto3.

jamesls avatar jamesls commented on September 18, 2024

@tianx2 I'd double check that the bucket actually is in us-east-1. I'm not seeing that issue when I try your sample code. For example, I created a bucket with dots in us-west-2. Running your sample code works for me:

>>> import boto3
>>> s3 = boto3.resource('s3', region_name='us-west-2')
>>> bucket = s3.Bucket('jamesls.bucket.with.dots')
>>> bucket.Tagging().tag_set
[{u'Value': 'TestValue', u'Key': 'TestTag'}]

However if I use the wrong region (say us-east-1 in this example), then I get your error:

>>> s3 = boto3.resource('s3', region_name='us-east-1')
>>> bucket = s3.Bucket('jamesls.bucket.with.dots')
>>> bucket.Tagging().tag_set
Traceback (most recent call last):
...
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (PermanentRedirect) when calling the GetBucketTagging operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

You can confirm where your bucket is located via:

>>> boto3.client('s3').get_bucket_location(Bucket='jamesls.bucket.with.dots')['LocationConstraint']
'us-west-2'

from boto3.

abhijeet55 avatar abhijeet55 commented on September 18, 2024

i tag the s3 bucket now i want to write a a program using boto3 to fetch the details of the tagging bucket can anyone help me in dat

from boto3.

asahr11 avatar asahr11 commented on September 18, 2024

getting error An error occurred (AuthorizationHeaderMalformed) when calling the GetBucketTagging operation: The authorization header is malformed; a non-empty Access Key (AKID) must be provided in the credential.

Any suggestions ?

from boto3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.