我正在尝试将Django应用程序部署到Elastic Beanstalk.当我访问页面时,它永远不会加载.日志说:
Script timed out before returning headers: wsgi.py
Run Code Online (Sandbox Code Playgroud)
我可以进入服务器并运行manage.py runserver,然后curl 127.0.0.1:8000从另一个终端运行,这将成功返回页面.所以我认为它必须是Apache配置的一个问题,它被设置为Elastic Beanstalk的一部分.
这里有更多的日志:
[pid 15880] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[so:warn] [pid 15880] AH01574: module wsgi_module is already loaded, skipping
[auth_digest:notice] [pid 15880] AH01757: generating secret for digest authentication ...
[lbmethod_heartbeat:notice] [pid 15880] AH02282: No slotmem from mod_heartmonitor
[mpm_prefork:notice] [pid 15880] AH00163: Apache/2.4.9 (Amazon) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[core:notice] [pid 15880] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[:error] [pid 15881] /opt/python/run/venv/lib/python2.7/site-packages/numpy/oldnumeric/__init__.py:11: …Run Code Online (Sandbox Code Playgroud) 我在虚拟环境中有一个名为python2.7inside的文件夹lib.
在阅读了六篇教程之后,我无法弄清楚我想将WSGIPythonPath指向的确切内容.我已经看到一些指向site-packages但有些已经是冒号:分隔列表.
Syntax error on line 1019 of /etc/httpd/conf/httpd.conf:
WSGIPythonPath cannot occur within <VirtualHost> section
Run Code Online (Sandbox Code Playgroud)
WSGIPythonPath应该指向我的virtualenv?
一直在使用mod_python,我读了越来越多关于WSGI有多好的文章,没有真正理解为什么.
那我为什么要切换到呢?有什么好处?这很难,学习曲线值得吗?
来自Python WSGI应用程序的以下代码片段是否可以从目录遍历中安全?它读取作为参数传递的文件名并返回指定的文件.
file_name = request.path_params["file"]
file = open(file_name, "rb")
mime_type = mimetypes.guess_type(file_name)[0]
start_response(status.OK, [('Content-Type', mime_type)])
return file
Run Code Online (Sandbox Code Playgroud)
我安装的应用程序下http://localhost:8000/file/{file}并送与URL的请求http://localhost:8000/file/../alarm.gif和http://localhost:8000/file/%2e%2e%2falarm.gif.但我没有尝试发送(现有)文件.那么我的代码在目录遍历中是否已经安全?
新的方法
似乎以下代码阻止目录遍历:
file_name = request.path_params["file"]
absolute_path = os.path.join(self.base_directory, file_name)
normalized_path = os.path.normpath(absolute_path)
# security check to prevent directory traversal
if not normalized_path.startswith(self.base_directory):
raise IOError()
file = open(normalized_path, "rb")
mime_type = mimetypes.guess_type(normalized_path)[0]
start_response(status.OK, [('Content-Type', mime_type)])
return file
Run Code Online (Sandbox Code Playgroud) Flask提供了一种url_for功能,可根据URL模式为处理程序生成URL.但这意味着处理程序函数必须在整个应用程序中具有唯一的名称.那是对的吗?
例
模块A有一个处理程序index:
@app.route('/')
def index(): pass
Run Code Online (Sandbox Code Playgroud)
模块B有另一个处理程序index:
@app.route('/anotherindex')
def index(): pass
Run Code Online (Sandbox Code Playgroud)
如何区分index构建URL时调用的处理程序?
url_for('index')
Run Code Online (Sandbox Code Playgroud) 我一直在使用Flask为我的k8055 USB接口板提供一个简单的Web API ; 相当标准的吸气剂和推杆,Flask真的让我的生活变得更轻松.
但我希望能够在乳清发生时将状态变化记录为/接近.
例如,如果我有一个连接到电路板的按钮,我可以轮询该特定端口的api.但如果我想让输出直接反映输出,无论是否有人在与api交谈,我都会有这样的事情.
while True:
board.read()
board.digital_outputs = board.digital_inputs
board.read()
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
每一秒,输出都会更新以匹配输入.
在Flask下有没有办法做这种事情?我之前在Twisted中做过类似的事情,但Flask对于这个特定的应用程序来说太方便了,只是放弃它...
谢谢.
这两个库共享相似的哲学和类似的设计决策.但是这个流行的WSGI基准测试表明eventlet速度比慢gevent.是什么让他们的表现如此不同?
据我所知,它们之间的主要区别是:
gevent故意取决于和被耦合到libev(libevent先前)而eventlet定义独立反应器接口并实现使用特定的适配器select,epoll和它后面扭曲反应器中.额外的反应器接口是否会产生关键性能?
gevent主要用Cython编写,而eventlet用纯Python编写.本机编译Cython比纯Python更快,对于计算量不大但是IO绑定的程序?
的原语gevent仿效标准库接口而eventlet的基元从标准不同,并提供额外的层来模拟它.额外的仿真层是否会eventlet变慢?
执行eventlet.wsgi情况比刚好差gevent.pywsgi吗?
我真的很好奇,因为它们对我来说总体看起来很相似.
我在AWS上有一个现有的Elastic Beanstalk烧瓶应用程序偶尔不会初始化并给出以下错误:
[Mon Jan 23 10:06:51.550205 2017] [core:error] [pid 7331] [client 127.0.0.1:43790] script timed out before returning headers: application.py
[Mon Jan 23 10:10:43.910014 2017] [core:error] [pid 7329] [client 127.0.0.1:43782] End of script output before headers: application.py
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样?最近我将项目requirements.txt改为包括在内pandas==0.19.2.在更改之前,程序将在返回相同错误之前工作几天.更多日志/计划详情:
[Mon Jan 23 10:05:36.877664 2017] [suexec:notice] [pid 7323] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Jan 23 10:05:36.886151 2017] [so:warn] [pid 7323] AH01574: module wsgi_module is already loaded, skipping
AH00557: httpd: apr_sockaddr_info_get() failed for ip-10-55-254-33
AH00558: httpd: Could not …Run Code Online (Sandbox Code Playgroud) 我想进行重定向并保留查询字符串.像self.redirect加上发送的查询参数之类的东西.那可能吗?
在我尝试让我的烧瓶应用程序在Apache上运行后反复失败后,我mod_wsgi决定尝试运行hello world示例.这是我的 -
目录结构(我将apache默认更改/var/www为~/public_html)
- public_html
- wsgi-scripts
- test_wsgi.wsgi
- test_wsgi
- test_wsgi.wsgi
Run Code Online (Sandbox Code Playgroud)
test_wsgi.wsgi文件
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Run Code Online (Sandbox Code Playgroud)
VirtualHost配置文件(称为testwsgi) - 驻留在 /etc/apache2/sites-enabled/
<VirtualHost *:80>
DocumentRoot ~/public_html/test_wsgi
<Directory ~/public_html/test_wsgi>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /wsgi ~/public_html/wsgi-scripts/test_wsgi.wsgi
<Directory ~/public_html/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
当我尝试localhost/wsgi使用浏览器时,我收到404 Not Found错误.我究竟做错了什么?这是我第一次尝试在生产服务器上部署应用程序.到目前为止,我采用了简单的方法来使用Google App Engine.我无法继续部署我的烧瓶应用程序,直到它启动并运行.非常感谢!
wsgi ×10
python ×8
mod-wsgi ×4
flask ×3
apache ×2
django ×2
api ×1
asyncsocket ×1
eventlet ×1
gevent ×1
performance ×1
python-2.7 ×1
security ×1
url ×1
url-routing ×1
web-services ×1
webapp2 ×1