【问题标题】:Cloud Storage Python Client Library needs memcache proxy on Ubuntu 14.04 VM InstanceCloud Storage Python 客户端库需要 Ubuntu 14.04 VM 实例上的 memcache 代理
【发布时间】:2015-01-09 17:07:07
【问题描述】:

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

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"

我的问题是:我会错过任何其他需要的模块/服务吗?从我找到的材料和文件中,没有提到任何内容。请注意,gsutil(命令行工具)按预期工作。

【问题讨论】:

    标签: python google-app-engine ubuntu google-cloud-storage


    【解决方案1】:

    您使用的是专门设计用于支持 Python 访问 从 App Engine 应用访问 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 实例中使用它,而不是普通 VM。 (在 GCE 虚拟机上安装 App Engine 的“托管虚拟机”设置也应该有效,但我相信这仍然是测试版/不受支持)。

    【讨论】:

    • 非常感谢您的回答。我想这就是我需要的例子。我会试试这个,它可能会起作用。我还尝试了 Python 中的 boto 模块,我可以访问我的存储桶。但是,我会尝试您建议的那个。再次感谢。
    猜你喜欢
    • 2014-07-20
    • 1970-01-01
    • 2014-08-11
    • 2014-09-25
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    相关资源
    最近更新 更多