Google App Engine 灵活环境中“无法导入 google/appengine/ext/deferred/handler.py”

2024-03-29

我使用 App Engine 灵活环境(以前称为托管虚拟机),最近升级到最新的 gcloud SDK。它包括一些新错误:

ERROR: (gcloud.preview.app.deploy) Error Response: [400] Invalid
character
in filename: lib/setuptools/script (dev).tmpl

ERROR: The [application] field is specified in file [.../app.yaml]. This field is not used
by gcloud and must be removed. Project name should instead be
specified either by `gcloud config set project MY_PROJECT` or by
setting the `--project` flag on individual command executions.

ERROR: (gcloud.preview.app.deploy) There is a Dockerfile in the
current directory, and the runtime field in
.../app.yaml is currently set to
[runtime: python27]. To use your Dockerfile to build a custom runtime,
set the runtime field in .../app.yaml
to [runtime: custom]. To continue using the [python27] runtime, please
omit the Dockerfile from this directory.

我修复了这些错误并能够再次发布,但开始看到如下错误:

Failed to import google/appengine/ext/deferred/handler.py
Traceback (most recent call last):
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/meta_app.py", line 549, in GetUserAppAndServe
    app, mod_file = self.GetUserApp(script)
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/meta_app.py", line 410, in GetUserApp
    app = _AppFrom27StyleScript(script)
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/meta_app.py", line 270, in _AppFrom27StyleScript
    app, filename, err = wsgi.LoadObject(script)
  File "/home/vmagent/python_vm_runtime/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
ImportError: Import by filename is not supported.

经过一番挖掘后,我明白了发生了什么。也就是说,处理这个的代码:

builtins:
- remote_api: on
- appstats: on
- deferred: on

托管 VM 已损坏。正确的解决方法是消除这些并内联内置包含。您可以找到相关的包含在这些子目录中 https://github.com/GoogleCloudPlatform/appengine-python-vm-runtime/tree/ae38e11c849d91bdf5d09cfe86e64dcace7c87f6/python_vm_runtime/google/appengine/ext/builtins:

就我而言,是将其添加到我的handlers:指示:

- url: /_ah/queue/deferred
  script: google.appengine.ext.deferred.application
  login: admin
- url: /_ah/stats.*
  script: google.appengine.ext.appstats.ui.app
- url: /_ah/remote_api(/.*)?
  script: google.appengine.ext.remote_api.handler.application

至于为什么,你可以在这里了解更多。在google/appengine/ext/builtins/__init__.py#L92 https://github.com/GoogleCloudPlatform/appengine-python-vm-runtime/blob/ae38e11c849d91bdf5d09cfe86e64dcace7c87f6/python_vm_runtime/google/appengine/ext/builtins/__init__.py#L92,它尝试使用以下命令查找相关的包含文件runtime:app.yaml 中的字段。这意味着它之前查找 deferred/include-python27.yaml,现在尝试查找 deferred/include-custom.yaml (由于修复了上述错误)并失败。所以现在它默认为 deferred/include.yaml,它按路径名而不是模块名列出包含脚本。然后,这会中断 python27-custom-VM 设置(因为它期望/需要模块名称)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google App Engine 灵活环境中“无法导入 google/appengine/ext/deferred/handler.py” 的相关文章

随机推荐