【发布时间】:2019-01-16 23:15:24
【问题描述】:
我正在尝试在 Google Cloud Platform 中创建一个小型服务器,用于接收图像并将其放入存储中。
但是当服务器部署时总是在日志中写入同样的错误:
ImportError:无法导入名称存储 在(/base/data/home/apps/my_environment/my_server:000000000000000.000000000000000000/main.py:15) 在 LoadObject (/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:85) 在 _LoadHandler (/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:299) 在句柄处 (/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:240)
我的功能是这样的:
from google.cloud import storage
...
def post_icon(request):
file = request.files['file']
package = request.form['package']
if file and _allowed_file(file.filename):
gcs = storage.Client()
bucket = gcs.get_bucket(CLOUD_STORAGE_APP_ICONS_SEGMENT)
blob = bucket.blob(file.filename)
blob.upload_from_string(
file.read(),
content_type=file.content_type
)
return {'code': 200 , 'message': blob.public_url }
else:
return {'code': 400 }
有人可以帮我吗?
【问题讨论】:
-
您的代码是在 App Engine 标准环境还是柔性环境中运行?
-
您是否按照google.cloud import storage: cannot import storage 中说明的步骤进行操作?
标签: python google-app-engine import