Open pstrzelczak opened 10 years ago
+1
Note- the HmacAuthV4Handler has this comment:
# You can set the service_name and region_name to override the # values which would otherwise come from the endpoint, e.g. #
. .amazonaws.com.
Seems like this is almost there.
(FWIW also- the JavaSDK supports this)
There IS a way to do it:
conn = S3Connection(...)
conn.auth_region_name = 'myregion'
bucket = conn.get_bucket('mybucket')
I wanted to check v4 authentication in a s3 compatible service using boto but I failed because boto seems to infer region from url and does not allow to use e.g. fixed region.
The code I used is the almost same as in https://github.com/boto/boto/issues/2623. The only difference is that a host is simply localhost.
What I got is: Traceback (most recent call last): File "v4Defect.py", line 27, in
connection.create_bucket("bucketname")
File "/home2/strzelczak/local/python2.6libs/boto/s3/connection.py", line 612, in create_bucket
data=data)
File "/home2/strzelczak/local/python2.6libs/boto/s3/connection.py", line 664, in make_request
retry_handler=retry_handler
File "/home2/strzelczak/local/python2.6libs/boto/connection.py", line 1053, in make_request
retry_handler=retry_handler)
File "/home2/strzelczak/local/python2.6libs/boto/connection.py", line 911, in _mexe
request.authorize(connection=self)
File "/home2/strzelczak/local/python2.6libs/boto/connection.py", line 375, in authorize
connection._auth_handler.add_auth(self, _kwargs)
File "/home2/strzelczak/local/python2.6libs/boto/auth.py", line 675, in add_auth
return super(S3HmacAuthV4Handler, self).add_auth(req, _kwargs)
File "/home2/strzelczak/local/python2.6libs/boto/auth.py", line 513, in add_auth
string_to_sign = self.string_to_sign(req, canonical_request)
File "/home2/strzelczak/local/python2.6libs/boto/auth.py", line 468, in string_to_sign
sts.append(self.credential_scope(http_request))
File "/home2/strzelczak/local/python2.6libs/boto/auth.py", line 450, in credential_scope
region_name = self.determine_region_name(http_request.host)
File "/home2/strzelczak/local/python2.6libs/boto/auth.py", line 618, in determine_region_name
return region_name
UnboundLocalError: local variable 'region_name' referenced before assignment
I tried to fix a region by using boto.config.set('Boto', 'autoscale_region_name', 'us-west-2') but it did not help.