Not sure if this is the same exact issue, but I found that all of my gcs requests from dev_appserver.py were getting routed to
localhost:8080/_ah/gcs/<BUCKET_NAME>/<OBJECT_NAME>
... as opposed to the "real" gcs url, e.g.
Therefore my GET requests to gcs always resulted in 404 errors.
After digging through the source code of
appengine-gcs-client, it looks like you must first set an access token if you would like to use dev_appserver to access live/remote content in gcs.
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'.
"""
global _access_token
_access_token = access_token
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.
"""
In short, I was able to remedy the issue by simply setting an access token, e.g.
cloudstorage.common.set_access_token("<TOKEN>")
See the note in set_access_token docstring about how to get an access token.
Once that I did that, all of my gcs requests were properly routed.
libs
pip
google-api-python-client==1.6.4
GoogleAppEngineCloudStorageClient==1.9.22.1
gcloud
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