Lilo
Lilo

Reputation: 59

Issue with using cloudstorage module in python

I am trying to upload directly to Google Cloud Storage from a series of URLs. I have been trying to implement the solution form here: How to upload an image from web into Google Cloud Storage?

In particular, whenever I try to open a file using cloudstorage module,

options={'x-goog-acl': 'public-read', 'Cache-Control': 'private, max-age=0, no-transform'}
with gcs.open(filename, 'w', content_type=content_type, options=options) as f:
    f.write(image_bytes)

I get the following error:


AttributeError                            Traceback (most recent call last)
<ipython-input-8-dec1a5d39c62> in <module>()
     18 
     19 options={'x-goog-acl': 'public-read', 'Cache-Control': 'private, max-age=0, no-transform'}
---> 20 with gcs.open(filename, 'w', content_type=content_type, options=options) as f:
     21     f.write(image_bytes)
     22     f.close()

AttributeError: 'module' object has no attribute 'open'

I have already tried installing cloudstorage in an isolated environment but still had no luck.

Based on the reference below, cloudstorage.open() exist in https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/functions

Any idea where the problem could be?

Thanks!

Upvotes: 3

Views: 4134

Answers (1)

Alex
Alex

Reputation: 5276

do print dir(gcs) to see what is in there. you may be installing a similarly named but different package.

It sounds like this is the one you want

https://github.com/GoogleCloudPlatform/appengine-gcs-client/tree/master/python/src/cloudstorage

and this is the function you are trying to use:

https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/python/src/cloudstorage/cloudstorage_api.py#L47

The readme.md for this repo points here:

https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/setting-up-cloud-storage

which says to do this:

pip install GoogleAppEngineCloudStorageClient -t <your_app_directory/lib>

Upvotes: 2

Related Questions