2
votes

I have a VM instance (Ubuntu 14.04) in the Google Cloud Platform where I'm doing tests with the Google Cloud Storage. What I want to do is to create a simple script that uses Cloud Storage Python Client Library. This script has to list the content of an existing bucket. Here is my script:

import logging
import os
import cloudstorage as gcs

from google.appengine.api import app_identity

# Retry can help overcome transient urlfetch or GCS issues, such as timeouts.
my_default_retry_params = gcs.RetryParams(initial_delay=0.2,
                                      max_delay=5.0,
                                      backoff_factor=2,
                                      max_retry_period=15)

gcs.set_default_retry_params(my_default_retry_params)

stats = gcs.listbucket('/niksa')

for f in stats:
    print f

I have installed cloudstorage Python module as shown in HERE. Then I updated the PYTHONPATH env variable to include the module. When running the script for the first time the script complained for missing module

ImportError: No module named google.appengine.api

To solve this, I installed Google App Engine by using the following command:

curl https://sdk.cloud.google.com/ | bash
gcloud components update gae-python

And then I updated the PYTHONPATH in my .bashrc to point to the parent folder containing the google python module.

When running once again the script, I got the following error:

AssertionError: No api proxy found for service "memcache"

My question is: Do I miss any other module/service needed? From the materials and documents I found, nothing has been mentioned. Note that gsutil (the command line tool) works as expected.

1

1 Answers

0
votes

You're using a library specifically designed to support Python access to GCS from an App Engine app. You don't have an app engine app (but rather a VM instance) so instead of that specialized library you should use the general purpose one found at https://developers.google.com/api-client-library/python/start/get_started .

The example is detailed at https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples , with the Python code for a complete example.

Alternatively, if you do want to use the client library you mentioned, you'll need to use it within an App Engine instance, not a plain VM. (A "managed VM" set-up, installing App Engine on a GCE VM, should also work, but I believe that's still beta/unsupported).