wabson opened a new issue #1417: InvalidCredsError when uploading .xlsm file to 
Google Storage bucket
URL: https://github.com/apache/libcloud/issues/1417
 
 
   ## Summary
   
   When running on Ubuntu it is not possible to upload an Excel macro-enabled 
file with the suffix `.xlsm` to a Google Storage bucket, the upload fails with 
an `InvalidCredsError` exception raised after calling 
`upload_object_via_stream()`
   
   ## Detailed Information
   
   I first noticed this in a Django app running on Heroku, and have since 
reproduced the issue with libcloud only, on standalone Ubuntu 16.04 and 18.04 
AMIs. The issue is triggered on Python2 and Python3 but does not occur on my 
OSX dev enviroment nor in testing on Amazon Linux. It does not reproduce when 
uploading to S3 and seems specific to GCP.
   
   Steps to reproduce:
   
   Create a bucket in Google Cloud Storage and in Storage Settings add an 
Access key for your account, under Interoperability.
   
   Install `apache-libcloud==2.8.0` via `pip`
   
   Attempt to upload a test file to the bucket as in the following example
   
   ```
   from io import BytesIO
   from libcloud.storage.types import Provider
   from libcloud.storage.providers import get_driver
   
   cls = get_driver(Provider.GOOGLE_STORAGE)
   driver = cls('my-access-key', 'my-secret')
   container = driver.get_container(container_name='my-test-bucket')
   obj = driver.upload_object_via_stream(iterator=BytesIO(b'hello'), 
container=container, object_name='test1.xlsm')
   ```
   
   This results in the following stack trace
   
   ```
   Traceback (most recent call last):
     File "upload.py", line 9, in <module>
       obj = driver.upload_object_via_stream(iterator=BytesIO(b'hello'), 
container=container, object_name='test1.xlsm')
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/storage/drivers/s3.py",
 line 698, in upload_object_via_stream
       storage_class=ex_storage_class)
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/storage/drivers/s3.py",
 line 842, in _put_object
       headers=headers, file_path=file_path, stream=stream)
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/storage/base.py", 
line 640, in _upload_object
       response.parse_error()
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/storage/drivers/s3.py",
 line 123, in parse_error
       raise InvalidCredsError(self.body)
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/common/base.py", line 
293, in body
       return self.response.body
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/common/base.py", line 
286, in response
       self.parse_error()
     File 
"/home/ubuntu/.local/lib/python3.6/site-packages/libcloud/storage/drivers/s3.py",
 line 123, in parse_error
       raise InvalidCredsError(self.body)
   libcloud.common.types.InvalidCredsError: b"<?xml version='1.0' 
encoding='UTF-8'?><Error><Code>SignatureDoesNotMatch</Code><Message>The request 
signature we calculated does not match the signature you provided. Check your 
Google secret key and signing 
method.</Message><StringToSign>PUT\n\napplication/vnd.ms-excel.sheet.macroEnabled.12\nSun,
 26 Jan 2020 22:45:12 
GMT\nx-goog-storage-class:STANDARD\n/hasler-race-entry-test/test1.xlsm</StringToSign></Error>"
   ```
   
   Changing the file extension in the object name to something more well-known 
such as `.xlsx` allows the operation to complete just fine, so I know the 
access credentials are working OK and it seems to be something to do with the 
mimetype.
   
   I notice that if I log in to the GCP Storage UI and upload a `.xlsm` file 
via the browser, it shows as having the type 
`application/vnd.ms-excel.sheet.macroenabled.12`, that is there is a small 
difference in case, I wonder if this is significant.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to