云存储 Python 客户端库需要 Ubuntu 14.04 VM 实例上的内存缓存代理

Cloud Storage Python Client Library needs memcache proxy on Ubuntu 14.04 VM Instance

我在 Google 云平台中有一个 VM 实例 (Ubuntu 14.04),我正在其中使用 Google 云存储进行测试。我想要做的是创建一个使用 Cloud Storage Python Client Library 的简单脚本。此脚本必须列出现有存储桶的内容。这是我的脚本:

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

我已经安装了 cloudstorage Python 模块,如 HERE 所示。然后我更新了 PYTHONPATH 环境变量以包含该模块。 当 运行 脚本第一次出现时,脚本抱怨缺少模块

ImportError: No module named google.appengine.api

为了解决这个问题,我使用以下命令安装了 Google App Engine:

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

然后我更新了 .bashrc 中的 PYTHONPATH 以指向包含 google python 模块的父文件夹。

再次运行脚本时,出现如下错误:

AssertionError: No api proxy found for service "memcache"

我的问题是:我是否遗漏了任何其他 module/service 需要的内容?从我查到的资料和文件来看,什么也没有提到。请注意,gsutil(命令行工具)按预期工作。

您正在使用专门设计用于支持从 App Engine 应用程序Python访问 GCS的库。您没有应用引擎应用程序(而是一个 VM 实例),因此您应该使用 https://developers.google.com/api-client-library/python/start/get_started 中的通用库而不是那个专用库。

示例在 https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples 中有详细说明,完整示例的 Python 代码。

或者,如果您确实想要使用您提到的客户端库,则需要在 App Engine 实例中使用它,不是 普通虚拟机。 ("managed VM" 设置,在 GCE VM 上安装 App Engine,应该也可以,但我相信那仍然是 beta/unsupported)。