Search code examples
pythongoogle-cloud-storagelibcloud

upload to google cloud storage using libcloud


I wish to to upload files to google cloud storage. I created a service account, converted the p12 file to a pem file, then referenced the service account email address and pem file in my driver:

from libcloud.storage.types import Provider
from libcloud.storage.providers import get_driver


CloudStorage = get_driver(Provider.GOOGLE_STORAGE)
driver = CloudStorage(
    '[email protected]',
    os.path.expanduser('~/.ssh/my.pem'),
    project='my_project',
)

however, when I do

driver.list_containers()

I get

<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidSecurity</Code><Message>The provided security credentials are not valid.</Message><Details>Incorrect Authorization header</Details></Error>

Solution

  • apache-libcloud uses the S3 protocol for Google Storage.

    This means you will need to enable Interoperability for Google Storage on the developer console.

    Instructions for doing this and generating the keys are available here