python - 目标 WSGI 脚本 '/opt/python/current/app/application.py' 不包含 WSGI 应用程序 'application'

标签 python amazon-web-services flask amazon-elastic-beanstalk

拔头发!我正在尝试将 Python FLask 应用程序部署到 AWS Elastic Beanstalk,但出现错误

目标 WSGI 脚本 '/opt/python/current/app/application.py' 不包含 WSGI 应用 'application'

网页刚刚返回 500 服务器错误

我的application.py内容如下:

#!/usr/bin/env python3
import connexion

if __name__ == '__main__':
    application = connexion.App(__name__, specification_dir='./swagger/')
    application.add_api('swagger.yaml', arguments={'title': 'This is a basic API fascade to theprotptype development robot. The API front-ends the communication with an MQTT pub/sub topic, which uses the Amazon Web Services IoT service.'})
    application.run()

在本地运行良好,但当我上传到 AWS 时就不行了。我已将名称从 app.py 更改为 application.py 并将 app = 更改为 application = 但没有更改

不知道下一步要去哪里:(

最佳答案

尝试在 application=... 之后移动 if __name__ == '__main__' 行,因为启动器可能导入您的脚本而不是执行它。在这种情况下,__name__ 将不会被定义为 __main__。看这个page为了更好的例子。

application = connexion.App(__name__, specification_dir='./swagger/')
application.add_api('swagger.yaml', arguments={'title': 'This is a basic API fascade to theprotptype development robot. The API front-ends the communication with an MQTT pub/sub topic, which uses the Amazon Web Services IoT service.'})
if __name__ == '__main__':
    application.run()

关于python - 目标 WSGI 脚本 '/opt/python/current/app/application.py' 不包含 WSGI 应用程序 'application',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37690918/

相关文章:

python - 类型错误 : 'str' object does not support item assignment (Python)

amazon-web-services - 如何在 Amazon S3 浏览器上查看直接链接?

amazon-web-services - 适用于 RDS 的 AWS 安全组 - 出站规则

amazon-web-services - 在 AWS 策略上的 Terraform 中使用模板文件,该策略使用 IAM 策略变量

flask - 为什么 Flask-Migrate 让我进行两步迁移?

python - 使用python的字符串插值

Python Flask send_file StringIO 空白文件

flask - 如何在 Flask-sqlalchemy 中使用 count()

python - 使用 Flask、SQLAlchemy 和 WTForms 更新多对多关系?

Python 3 == 运算符