简体   繁体   English

ImportError - 将Falcon应用程序部署到AWS Elastic Beanstalk

[英]ImportError - deploy Falcon app to AWS Elastic Beanstalk

I'm having an ImportError after deploying to Elastic Beanstalk. 我在部署到Elastic Beanstalk后遇到了ImportError。 We're running Falcon to make an API. 我们正在运行Falcon来制作API。 I have successfully used the EB CLI to initialise an app, create the environment and deploy my code. 我已成功使用EB CLI初始化应用程序,创建环境并部署我的代码。 We use Python 2.7 (for now). 我们使用Python 2.7(现在)。

The AWS EB site for the app/environment says everything went well, but when I send a request to the api, the logs show this error: 应用程序/环境的AWS EB站点说一切顺利,但是当我向api发送请求时,日志会显示以下错误:

[Wed Nov 30 06:02:25.555507 2016] [:error] [pid 29352] [remote 127.0.0.1:56624] Traceback (most recent call last):
[Wed Nov 30 06:02:25.555524 2016] [:error] [pid 29352] [remote 127.0.0.1:56624]   File "/opt/python/current/app/api/app.py", line 12, in <module>
[Wed Nov 30 06:02:25.555549 2016] [:error] [pid 29352] [remote 127.0.0.1:56624]     from middlewares import require_json
[Wed Nov 30 06:02:25.555566 2016] [:error] [pid 29352] [remote 127.0.0.1:56624] ImportError: No module named middlewares
[Wed Nov 30 06:02:26.558411 2016] [:error] [pid 29352] [remote 127.0.0.1:60720] mod_wsgi (pid=29352): Target WSGI script '/opt/python/current/app/api/app.py' cannot be loaded as Python module.

Locally my imports work just fine. 本地我的进口工作得很好。 The relevant parts of the api look like this: api的相关部分如下所示:

-api/
    -__init__.py #import app
    -app.py
    -middlewares/
        -__init__.py #import require_json
        -require_json.py

Line 12 of my app.py file: 我的app.py文件的第12行:

from middlewares import require_json

But the logs are consistently saying this is an ImportError. 但是日志一直在说这是一个ImportError。 Any thoughts on what's happened here? 关于这里发生了什么的任何想法? I'm baffled. 我很困惑。

As for the __init__.py files importing modules; 至于__init__.py文件导入模块; this is a legacy code base and I'm not sure what the implications are for changing that just yet, other than the tests will fail. 这是一个遗留代码库,我不确定改变它的含义是什么,除了测试失败。

EDIT 编辑

This morning I've tried commenting out those import lines, but that just gives me errors on the next import: 今天早上我尝试评论出那些导入行,但这只会让我在下次导入时出错:

[Wed Nov 30 21:52:00.699228 2016] [:error] [pid 11254] [remote 172.31.8.163:37352] Traceback (most recent call last):
[Wed Nov 30 21:52:00.699245 2016] [:error] [pid 11254] [remote 172.31.8.163:37352]   File "/opt/python/current/app/api/app.py", line 15, in <module>
[Wed Nov 30 21:52:00.699270 2016] [:error] [pid 11254] [remote 172.31.8.163:37352]     import resources
[Wed Nov 30 21:52:00.699288 2016] [:error] [pid 11254] [remote 172.31.8.163:37352] ImportError: No module named resources

I've also done what's recommended in this article . 我也完成了本文的建议。

import sys
sys.path.insert(0, '/opt/python/current/app')

With the way your code appears to be structured, you shouldn't be pointing WSGIScriptAlias directive of Apache at your app.py file directly. 使用您的代码的结构化方式,您不应该直接在app.py文件中指向Apache的WSGIScriptAlias指令。

What you need to do is create a separate WSGI script file to use with WSGIScriptAlias and in it have: 您需要做的是创建一个单独的WSGI脚本文件以与WSGIScriptAlias一起使用,其中包含:

from api.app import application

You will also need to configure mod_wsgi so that the parent directory of the api directory is in the Python module search path. 您还需要配置mod_wsgi,以便api目录的父目录位于Python模块搜索路径中。 You can do in the mod_wsgi configuration, or do it in this new WSGI script file. 您可以在mod_wsgi配置中执行,也可以在此新的WSGI脚本文件中执行此操作。

Presuming you had added the WSGI script file as app.wsgi in the same directory as api appears as a subdirectory, it could include: 假设您已将WSGI脚本文件作为app.wsgi添加到与api显示为子目录的同一目录中,它可能包括:

import os
import sys

sys.path.insert(0, os.path.dirname(__file__))

from api.app import application

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

相关问题 尝试将Flask App部署到AWS Elastic Beanstalk时出错 - Error when Trying to Deploy Flask App to AWS Elastic Beanstalk 如何使用应用程序工厂将Flask应用程序部署到AWS Elastic beantalk - How to deploy Flask app to AWS Elastic beanstalk using an application factory 如何将具有多个 Docker 容器的应用程序部署到 AWS Elastic Beanstalk? - How to deploy an app with multiple Docker containers to AWS Elastic Beanstalk? 如何在AWS弹性beanstalk上部署结构化Flask应用程序 - How to deploy structured Flask app on AWS elastic beanstalk AWS Elastic Beanstalk 错误我无法部署 - AWS Elastic Beanstalk error I cannot deploy 在AWS Elastic Beanstalk上部署python Web服务器 - Deploy python web server on AWS Elastic Beanstalk 将 Dash 和 assets 文件夹部署到 AWS Elastic Beanstalk - Deploy Dash with assets folder to AWS Elastic Beanstalk 无法在弹性beantalk上部署django应用 - Not able to deploy the django app on elastic beanstalk 在AWS Elastic Beanstalk上进行Django App Deploy错误:关系“ django_site”不存在 - Django App Deploy on AWS Elastic Beanstalk Error: relation “django_site” does not exist 我试图在 AWS 弹性豆茎上部署 flask 应用程序,但收到此错误 - I was trying to deploy a flask app on AWS elastic beanstalk, but am getting this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM