拔头发!我正在尝试将 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/