簡體   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