【问题标题】:Target WSGI script '/opt/python/current/app/application.py' does not contain WSGI application 'application'目标 WSGI 脚本 '/opt/python/current/app/application.py' 不包含 WSGI 应用程序 'application'
【发布时间】:2016-10-08 00:54:50
【问题描述】:

拔掉我的头发!我正在尝试将 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 = 但没有更改

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

【问题讨论】:

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


    【解决方案1】:

    尝试将if __name__ == '__main__' 行移到application=... 之后,因为启动器可能导入您的脚本而不是执行它。在这种情况下,__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()
    

    【讨论】:

    • 谢谢,它向前移动了,现在它通过了它并失败,并出现 'AttributeError: 'module' object has no attribute 'default_controller'' :) :(
    • 似乎您的本地软件包与AWS上的软件包版本不同。检查这些相关包的版本号。
    猜你喜欢
    • 2017-08-18
    • 2018-11-11
    • 2016-04-11
    • 2013-08-27
    • 2021-11-28
    • 2020-05-17
    • 1970-01-01
    • 2018-04-01
    相关资源
    最近更新 更多