简体   繁体   English

在本地 devappserver 上使用 google-api-go-client

[英]Using google-api-go-client on local devappserver

I am writing an application that will be running on GCE and am using the google-api-go-client from https://code.google.com/p/google-api-go-client/ to store data in GCS.我正在编写一个将在 GCE 上运行的应用程序,并使用https://code.google.com/p/google-api-go-client/ 中的 google-api-go-client 将数据存储在 GCS 中。

I have a GAE application running as well that the GCE application communicates with.我还有一个 GAE 应用程序正在运行,GCE 应用程序与之通信。

I can run my GCE application locally and communicate with the live GCS servers and store files and retrieve them.我可以在本地运行我的 GCE 应用程序并与实时 GCS 服务器通信并存储文件并检索它们。

Now I am trying to locally store files in GCS so that I can run a test environment.现在我正在尝试将文件本地存储在 GCS 中,以便我可以运行测试环境。

I see that devappserver supports simulating GCS via blobstore.我看到 devappserver 支持通过 blobstore 模拟 GCS。 However I can't seem to figure out how to point my GCE application at the local devappserver for GCS storage.但是,我似乎无法弄清楚如何将我的 GCE 应用程序指向本地 devappserver 以进行 GCS 存储。

I am running a devappserver through 'goapp serve' with my GAE application.我正在使用我的 GAE 应用程序通过“goapp serve”运行 devappserver。

I have tried setting the basepath and that results in 500 errors from the devappserver.我曾尝试设置基本路径,结果导致 devappserver 出现 500 个错误。

service, err := storage.New(httpClient)
service.BasePath = "http://localhost:8080/_ah/gcs/"

results in结果是

ERROR    2014-10-23 19:14:08,692 module.py:727] Request to '/_ah/gcs/b/default/o/6051711999279104' failed
Traceback (most recent call last):
  File "/home/ben/go_appengine/google/appengine/tools/devappserver2/module.py", line 723, in _handle_request
    return handler.handle(match, environ, wrapped_start_response)
  File "/home/ben/go_appengine/google/appengine/tools/devappserver2/wsgi_handler.py", line 59, in handle
    return self._wsgi_app(environ, start_response)
  File "/home/ben/go_appengine/google/appengine/tools/devappserver2/gcs_server.py", line 56, in __call__
    status_message = httplib.responses.get(e.args[1], '')
IndexError: tuple index out of range
INFO     2014-10-23 19:14:08,693 module.py:652] default: "GET /_ah/gcs/b/default/o/6051711999279104?alt=json HTTP/1.1" 500 -

I can point my browser to this URL我可以将浏览器指向此 URL

http://localhost:8080/_ah/gcs/bucket

and get an XML result:并得到一个 XML 结果:

<ListBucketResult xmlns="http://doc.s3.amazonaws.com/2006-03-01">
    <IsTruncated>False</IsTruncated>
</ListBucketResult>

I have seen several posts about using GCS locally but I can't seem to get it working correctly.我看过几篇关于在本地使用 GCS 的帖子,但我似乎无法让它正常工作。 Is there something I am doing wrong here?我在这里做错了吗? Or does devappserver not support GCS or maybe its just the json api it doesn't support?还是 devappserver 不支持 GCS 或者它只是它不支持的 json api?

I want to make sure we're clear on the distinction between the "Google APIs Client Library for Go", which is a general-purpose Google API client for Go that can be used to access the Google Cloud Storage JSON API, and App Engine's "Google Cloud Storage Go Client", which is a client library specific to App Engine users who want to use Google Cloud Storage.我想确保我们清楚“Google APIs Client Library for Go”之间的区别,它是 Go 的通用 Google API 客户端,可用于访问 Google Cloud Storage JSON API,与 App Engine 的“Google Cloud Storage Go Client”,这是一个特定于想要使用 Google Cloud Storage 的 App Engine 用户的客户端库。

There are two Google Cloud Storage APIs: JSON and XML.有两个 Google Cloud Storage API:JSON 和 XML。 The general purpose Google APIs Client Library is compatible with the JSON API.通用 Google API 客户端库与 JSON API 兼容。 The App Engine Google Cloud Storage Go Client speaks XML API. App Engine Google Cloud Storage Go Client 使用 XML API。

The App Engine client libary fully supports local operations. App Engine 客户端库完全支持本地操作。 This is accomplished by providing a local implementation of the Google Cloud Storage XML API, which the client library uses.这是通过提供客户端库使用的 Google Cloud Storage XML API 的本地实现来实现的。 Unfortunately, only the XML API exists locally, and thus only the App Engine client library works locally.不幸的是,只有 XML API 存在于本地,因此只有 App Engine 客户端库在本地工作。 Pointing the other client to it will fail because the XML API doesn't understand the incoming JSON API requests.将另一个客户端指向它会失败,因为 XML API 不理解传入的 JSON API 请求。

Your two best options are to do one of the following:您的两个最佳选择是执行以下操作之一:

  1. Use the Google Cloud Storage Go Client Library for App Engine.使用适用于 App Engine 的Google Cloud Storage Go 客户端库 Download instructions are here .下载说明在这里
  2. Instead of using a local implemention, use the real Google Cloud Storage with a test bucket.不要使用本地实现,而是使用带有测试存储桶的真实 Google Cloud Storage。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM