我正在尝试在我的应用引擎项目上使用谷歌远程 API 将本地文件上传到我的应用的默认云存储桶。
我已将我的 app.yaml 配置为启用远程 api。我能够访问我的存储桶并从中上传/访问文件。我运行我的本地 python 控制台并尝试使用以下代码写入存储桶:
from google.appengine.ext.remote_api import remote_api_stub
from google.appengine.api import app_identity
import cloudstorage
def auth_func():
return ('user@gmail.com', '*******')
remote_api_stub.ConfigureRemoteApi('my-app-id', '/_ah/remote_api', auth_func,'my-app-id.appspot.com')
filename = "/"+app_identity.get_default_gcs_bucket_name()+ "/myfile.txt"
gcs_file = cloudstorage.open(filename,'w',content_type='text/plain',options={'x-goog-meta-foo': 'foo','x-goog-meta-bar': 'bar'})
我看到以下响应:
WARNING:root:suspended generator urlfetch(context.py:1214) raised DownloadError(Unable to fetch URL: http://None/_ah/gcs/my-app-id.appspot.com/myfile.txt)
注意
http://None/_ah/gcs.....
我不认为 None 应该是 url 的一部分。 GoogleAppEngineCloudStorageClient v1.9.0.0 有问题吗?我也在使用 Google App Engine 1.9.1。
有什么想法吗?
请您参考如下方法:
Google Cloud Storage 客户端不遵守 remote_api_stub 并认为您在本地运行脚本
os.environ['SERVER_SOFTWARE'] = 'Development (remote_api)/1.0'
甚至
os.environ['SERVER_SOFTWARE'] = ''
会有帮助。
函数,从common.py检查你的环境
def local_run():
"""Whether we should hit GCS dev appserver stub."""
server_software = os.environ.get('SERVER_SOFTWARE')
if server_software is None:
return True
if 'remote_api' in server_software:
return False
if server_software.startswith(('Development', 'testutil')):
return True
return False
