IBM / ibm-cos-sdk-python

ibm-cos-sdk-python
Apache License 2.0
45 stars 26 forks source link

SignatureDoesNotMatch on Object.put only. #20

Closed rawkintrevo closed 5 years ago

rawkintrevo commented 5 years ago

UPDATE:

ibm_boto3.__version__
Out[3]: 
'2.3.3'

I'm trying to do a thing, but hitting an issue when writing data to IBM COS (S3)

This code

import ibm_boto3
from ibm_botocore.client import Config

# Constants for IBM COS values
COS_ENDPOINT = "s3-api.us-geo.objectstorage.softlayer.net" # Current list avaiable at https://cos-service.bluemix.net/endpoints
ENDPOINT_URL = "https://" + COS_ENDPOINT

# Create resource
cos = ibm_boto3.resource("s3",
                         aws_access_key_id= "obviNo", #just for example
                         aws_secret_access_key= "obviStillNo", # same
                         region_name= "us-geo",
                         endpoint_url= ENDPOINT_URL,
                         # ibm_service_instance_id=COS_RESOURCE_CRN,
                         # ibm_auth_endpoint=COS_AUTH_ENDPOINT,
                         # config=Config(signature_version="oauth")
                         # endpoint_url=COS_ENDPOINT
                         )

print("List all the buckets:")
buckets = cos.buckets.all()
for bucket in buckets:
    print("Bucket Name: {0}".format(bucket.name))
print("---------------------------------")
print("List all the files in the last bucket:")
files = cos.Bucket(bucket.name).objects.all()
for file in files:
    print("Item: {0} ({1} bytes).".format(file.key, file.size))
print("---------------------------------")
print("Create a silly text file:")
file_data = "bab bab booey\nthey wont like that."
cos.Object(bucket.name, "foo.txt").put(
    Body= file_data #,
    # ServerSideEncryption='aws:kms'
)

yields this result:

List all the buckets:
Bucket Name: mnist-bucket-tutorial
---------------------------------
List all the files in the last bucket:
Item: 0.png (324 bytes).
Item: 1.png (145 bytes).
Item: 2.png (289 bytes).
Item: 3.png (250 bytes).
Item: 4.png (263 bytes).
Item: 5.png (295 bytes).
Item: 6.png (259 bytes).
Item: 7.png (219 bytes).
Item: 8.png (284 bytes).
Item: 9.png (261 bytes).
---------------------------------
Create a silly text file:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2869, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-0735ae91a378>", line 34, in <module>
    Body= file_data #,
  File "/usr/local/lib/python3.6/dist-packages/ibm_boto3/resources/factory.py", line 517, in do_action
    response = action(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/ibm_boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/usr/local/lib/python3.6/dist-packages/ibm_botocore/client.py", line 255, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.6/dist-packages/ibm_botocore/client.py", line 545, in _make_api_call
    raise error_class(parsed_response, operation_name)
ibm_botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. For more information, see REST Authentication and SOAP Authentication for details.

Have been googling for an hour but can't seem to make anything work- have tried new creds, have used "reader" "writer" and "manager" creds, none work. Can't seem to get it- pls help!

seamus-mcgrath commented 5 years ago

Hi @rawkintrevo can you try changing the config to; config=Config(signature_version='s3v4'))

And let me know if this works?

rawkintrevo commented 5 years ago

Ahh- that does work. At a minimum I think someone (maybe me?) needs to update this: https://console.bluemix.net/docs/services/cloud-object-storage/libraries/python.html#using-python

seamus-mcgrath commented 5 years ago

@rawkintrevo are you happy to close this issue now?

rawkintrevo commented 5 years ago

Yea- updating docs would be my only comment, but I'm closing issue now.