繁体   English   中英

具有云存储功能的Google App Engine无法在本地运行

[英]Google App Engine with Cloud Storage not Working Locally

我正在Google Appengine上运行一个Wordpress网站。 它使用GAE插件进行wordpress。 媒体库适用于appengine服务器,但不适用于本地服务器。 大多数图像也是如此,除非它们具有硬编码链接。 我收到了大量的404错误......

http://localhost:8080/_ah/gcs/<BUCKET_NAME>/image.png Failed to load resource: the server responded with a status of 404 (Not Found)

gae服务器上的此链接的工作原理:

http://<BUCKET_NAME>.storage.googleapis.com/image.png

我在本地运行我的应用程序如下: dev_appserver.py --php_executable_path=/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/php55/php-cgi .

看来谷歌的python脚本没有正确转发链接到实际真正的桶....任何想法?

这是预期的行为:

链接http://<BUCKET_NAME>.storage.googleapis.com/image.png是生产链接,请求从生产服务器提供。

链接http://localhost:8080/_ah/gcs/<BUCKET_NAME>/image.png是本地链接,devserver实际上必须包含<BUCKET_NAME>/image.png 该对象可能仅存储在生产中,在尝试在本地计算机上找到它时会导致404。

作为一种解决方案,您可以考虑简单地针对生产云存储运行本地测试,以节省将所有存储项目传输(并保持同步)到本地的成本,这几乎肯定会在网络传输和开发中花费更多。时间比这个更简单的选择。

不确定这是否是同一个问题,但我发现来自dev_appserver.py的所有gcs请求都被路由到

http://localhost:8080/_ah/gcs/<BUCKET_NAME>/<OBJECT_NAME>

...而不是“真正的”gcs网址,例如

https://www.googleapis.com/storage/v1/b/<BUCKET_NAME>/<OBJECT_NAME>

...因此在对gcs对象进行GET请求时会导致404错误。

TLDR

我能够通过简单地设置访问令牌来解决这个问题,例如

cloudstorage.common.set_access_token("<TOKEN>")

*有关如何获取访问令牌的信息,请参阅下面的set_access_token文档字符串。

一旦我这样做,我的所有gcs请求都被正确路由。

细节

在深入了解appengine-gcs-client源代码后,如果您想使用dev_appserver访问gcs中的实时/远程内容,您似乎必须首先设置访问令牌。

cloudstorage.common中

def set_access_token(access_token):
  """Set the shared access token to authenticate with Google Cloud Storage.
  When set, the library will always attempt to communicate with the
  real Google Cloud Storage with this token even when running on dev appserver.
  Note the token could expire so it's up to you to renew it.
  When absent, the library will automatically request and refresh a token
  on appserver, or when on dev appserver, talk to a Google Cloud Storage
  stub.
  Args:
    access_token: you can get one by run 'gsutil -d ls' and copy the
      str after 'Bearer'.
  """

cloudstorage.storage_api中的一些其他提示/选项:

def _get_storage_api(retry_params, account_id=None):
  """Returns storage_api instance for API methods.
  Args:
    retry_params: An instance of api_utils.RetryParams. If none,
     thread's default will be used.
    account_id: Internal-use only.
  Returns:
    A storage_api instance to handle urlfetch work to GCS.
    On dev appserver, this instance will talk to a local stub by default.
    However, if you pass the arguments --appidentity_email_address and
    --appidentity_private_key_path to dev_appserver.py it will attempt to use
    the real GCS with these credentials.  Alternatively, you can set a specific
    access token with common.set_access_token.  You can also pass
    --default_gcs_bucket_name to set the default bucket.
  """

其他信息

pip libs

google-api-python-client==1.6.4
GoogleAppEngineCloudStorageClient==1.9.22.1

gcloud libs

Google Cloud SDK 200.0.0
alpha 2018.04.30
app-engine-python 1.9.69
app-engine-python-extras 1.9.69
beta 2018.04.30
bq 2.0.33
cloud-datastore-emulator 1.4.1
core 2018.04.30
gsutil 4.31

暂无
暂无

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

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