简体   繁体   English

Google App Engine Python:部署时出现 yaml 配置文件错误

[英]Google App Engine Python: Error in yaml config file when deploying

I'm using Google App Engine, Python37 environment.我正在使用 Google App Engine,Python37 环境。 I got an error message when trying to deploy a microservice today:我今天尝试部署微服务时收到一条错误消息:
I run the command:我运行命令:

gcloud app deploy app.yaml

Got the error:得到错误:

...
File upload done.
ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: script field for handler '/.*' 
must be set to 'auto' for runtime python37.
PS C:\path_to_app> gcloud app deploy app.yaml
...

My app.yaml is:我的 app.yaml 是:

service: service_name
runtime: python37

handlers:
- url: /.*
script: main.py

It looks exactly the same from other microservices that I have deployed recently, just the service name is different.和我最近部署的其他微服务看起来完全一样,只是服务名称不同。
I tried to re-deploy a services that is already running and got same error message.我试图重新部署一个已经在运行的服务并收到相同的错误消息。
So I double check app.yaml reference document: https://cloud.google.com/appengine/docs/standard/python3/config/appref所以我仔细检查了 app.yaml 参考文档: https : //cloud.google.com/appengine/docs/standard/python3/config/appref
But I couldn't find out what is wrong neither why the same yaml file that had worked before doesn't work anymore.但是我无法找出问题所在,也找不到为什么以前工作过的同一个 yaml 文件不再工作了。

Does anyone know what can be wrong or maybe what can be changed on Google App Engine in the last days?有谁知道最近几天 Google App Engine 上可能出了什么问题,或者可能会发生什么变化?

Thanks in advance.提前致谢。

As per the AppEngine documentation for Python 3.7,根据 Python 3.7 的AppEngine 文档

The only accepted value for the script element is auto脚本元素唯一接受的值是auto

Below is a sample entry from the documentation:以下是文档中的示例条目:

handlers:
- url: /images
  static_dir: static/images

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

The earlier answer from @Omair , while correct, is only part of the story. @Omair的早期答案虽然正确,但只是故事的一部分。 The OP's original question utilizes an App Engine first-generation ("Gen1") runtime app's app.yaml configuration file where the routing happens, requiring the script: directive in handlers: . OP 的原始问题利用了 App Engine 第一代(“Gen1”)运行时应用程序的app.yaml配置文件,其中发生路由,需要handlers:script:指令handlers: While that's a perfectly valid app.yaml for a Gen1 ( go111 , python [2.5], python27 , php55 ) app, it won't work for next generation ("Gen2") apps.虽然这是一个完全有效app.yaml的第一代( go111python [2.5], python27php55 )的应用程序,它会为下一代(“第二代”)不工作的应用程序。

NOTE: Python 2 is only supported by App Engine Gen1 whereas Python 3 is only supported by App Engine Gen2 (Standard or Flex), so if you migrate from Python 2 to 3, you're also porting from Gen1 to Gen2 and need to keep in mind these differences as well.注意: Python 2 仅受 App Engine Gen1 支持,而 Python 3 仅受 App Engine Gen2(Standard 或 Flex)支持,因此如果您从 Python 2 迁移到 3,您也会从 Gen1 移植到 Gen2,并且需要保持还要记住这些差异。 (Unfortunately, this means migrating from webapp2 to a web framework that handles routing, ie, Django, Flask, etc.) (不幸的是,这意味着从webapp2迁移到处理路由的 web 框架,即 Django、Flask 等)

App Engine Gen2 requires routing to be done by your framework . App Engine Gen2要求路由由您的框架完成 As a result, all Gen1 app.yaml files need to be updated.因此,所有 Gen1 app.yaml文件都需要更新。 Use of handlers: for your routes must be either removed or changed to auto (because it's done by your web framework now). handlers:使用handlers:因为您的路由必须被删除或更改为auto (因为它现在由您的 Web 框架完成)。 If you have specific app startup instructions, you can provide an entrypoint: directive ;如果您有特定的应用程序启动说明,您可以提供一个entrypoint:指令 check out these examples .看看这些例子

Both handlers: and entrypoint: are optional. handlers:entrypoint:都是可选的。 If all script handlers are auto , you don't need handlers: unless your app is serving static files like client-side JS, CSS, HTML, images, etc., and entrypoint: is optional because if you don't specify a server, gunicorn is selected (and started) by default.如果所有脚本处理程序都是auto ,则不需要handlers:除非您的应用程序提供静态文件,如客户端 JS、CSS、HTML、图像等,并且entrypoint:是可选的,因为如果您不指定服务器,默认情况下会选择(并启动) gunicorn Basically if you take all the defaults and don't serve static files, you can reduce app.yaml down to 1 line, like this one .基本上,如果您采用所有默认值并且不提供静态文件,您可以将app.yaml减少到 1 行,就像这样 That sample is from a repo I'm working on to help developers upgrade Python 2 App Engine apps to Python 3 who need more help than what's available in the official migration guide .该示例来自我正致力于帮助开发人员将 Python 2 App Engine 应用程序升级到 Python 3 的存储库,他们需要比官方迁移指南中提供的更多帮助。

I got this error when deploying a flask app with a blueprint structure.部署具有蓝图结构的 Flask 应用程序时出现此错误。 The solution is to have main.py file in the same directory as app.yaml file.解决方案是将main.py文件与app.yaml文件放在同一目录中。 In the main.py file, import the app object eg from app import app (here the first 'app' is the folder containing an init file where the flask app instance is created).main.py文件中,导入 app 对象,例如from app import app (这里的第一个“app”是包含init文件的文件夹,在其中创建了main.py应用程序实例)。 After doing this, setting script to auto should work fine.执行此操作后,将脚本设置为自动应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM