wsgi 错误:无法为请求和请求获取桶旅apache2 重定向帖子以获取? [英] wsgi error: Unable to get bucket brigade for request & apache2 redirects post to get?

查看:30
本文介绍了wsgi 错误:无法为请求和请求获取桶旅apache2 重定向帖子以获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用部署在 apache2 上的 Flask 应用程序处理发布请求,但我意外重定向.它也会丢失请求正文.我使用网络应用程序触发发布请求,访问日志显示:57.39.118.158 - - [22/Dec/2017:11:44:32 +0300] "POST/bridge HTTP/1.1" 301 3830 "-" "-"57.39.118.158 - - [22/Dec/2017:11:44:32 +0300] "GET/bridge/HTTP/1.1" 500 860 "-" "-" 和错误日志:[2017 年 12 月 22 日星期五 11:44:51.864122] [wsgi:error] [pid 28906:tid 139849921148672] (70008) 部分结果有效但处理不完整:[client 57.39.118_17208: mod35218g728: mod352117208.15]: 无法获得铲斗队的请求."之前,404 url​​ 的url not found"问题apache2 上的flask 应用程序未找到错误已解决.

I want to handle a post request with a Flask app deployed on apache2 but I got unintended redirection. it also looses request body. I trigger a post request using a web app and access log says: 57.39.118.158 - - [22/Dec/2017:11:44:32 +0300] "POST /bridge HTTP/1.1" 301 3830 "-" "-" 57.39.118.158 - - [22/Dec/2017:11:44:32 +0300] "GET /bridge/ HTTP/1.1" 500 860 "-" "-" and error log: "[Fri Dec 22 11:44:51.864122 2017] [wsgi:error] [pid 28906:tid 139849921148672] (70008)Partial results are valid but processing is incomplete: [client 57.39.118.158:35172] mod_wsgi (pid=28906): Unable to get bucket brigade for request." Before, the problem "url not found" at 404 url not found error for flask app on apache2 is solved.

我使用的是 python 3.5.2、apache 2.4、OpenSSL/1.0.2g、ubuntu 16.04、为 python 3.5.1+ 编译的 mod_wsgi4.3.0

I'm using python 3.5.2, apache 2.4, OpenSSL/1.0.2g, ubuntu 16.04, mod_wsgi4.3.0 compiled for python 3.5.1+

我启用了一个唯一的 conf 文件,如下所示:

I have a unique conf file enabled and is like this:

<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName newocto.org
DocumentRoot /var/www/html

SSLEngine on
SSLCertificateFile /etc/ssl/certs/newocto_org.crt
SSLCertificateKeyFile /etc/ssl/private/newocto.key
SSLCertificateChainFile /etc/ssl/certs/COMODORSAAddTrustCA.crt


# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

WSGIDaemonProcess bridge user=dogacandu group=dogacandu threads=5 home=/var/www/bridge/
WSGIScriptAlias /bridge /var/www/bridge/bridge.wsgi


<Directory /var/www/bridge>
WSGIProcessGroup bridge
WSGIApplicationGroup %{GLOBAL}
Require all granted

</Directory>

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

位于/var/www/bridge/bridge.wsgi 的文件是

file at /var/www/bridge/bridge.wsgi is

#!/usr/bin/python3
import sys


sys.path.insert(0,'/var/www/bridge')

from bridge import app as application

位于/var/www/bridge/bridge.py 的文件是

file at /var/www/bridge/bridge.py is

#!/usr/bin/python3

from flask import Flask


app = Flask(__name__)

@app.route('/', methods =['POST'])
def deliver():
    from flask import request
    raw=request.get_json(force=True)
    import mysql.connector
    dbconn= mysql.connector.connect(host='xx.20.xxx.245',port='3306',database='xxa',user='root',password='Jxxxo')
    cursor=dbconn.cursor()
    query1="""insert into bridge_test2 (email) values ('blah')"""
    query2="""insert into bridge_test2 (email) values ('{}')""".format(raw)
    cursor.execute(query1)
    dbconn.commit()
    cursor.execute(query2)
    dbconn.commit()
    dbconn.close()
    return 'ok'

if __name__ == '__main__':
   app.run()

文件权限:

4 -rwxr-xr-x 1 root dogacandu 654 Dec 21 17:31 bridge.py  
4 -rwxr-xr-x 1 root dogacandu 117 Dec 20 18:26 bridge.wsgi

dogacandu 是具有 sudo 权限的用户.启用的模组是:

dogacandu is user with sudo privilage. enabled mods are:

access_compat.load authn_core.load authz_user.load cgid.load dir.load mime.load协商.load socache_shmcb.load status.loadalias.conf authn_file.load autoindex.conf deflate.conf env.load mpm_event.conf rewrite.load ssl.conf wsgi.confalias.load authz_core.load autoindex.load deflate.load filter.load mpm_event.load setenvif.conf ssl.load wsgi.loadauth_basic.load authz_host.load cgid.conf dir.conf mime.conf协商.conf setenvif.load status.conf

access_compat.load authn_core.load authz_user.load cgid.load dir.load mime.load negotiation.load socache_shmcb.load status.load alias.conf authn_file.load autoindex.conf deflate.conf env.load mpm_event.conf rewrite.load ssl.conf wsgi.conf alias.load authz_core.load autoindex.load deflate.load filter.load mpm_event.load setenvif.conf ssl.load wsgi.load auth_basic.load authz_host.load cgid.conf dir.conf mime.conf negotiation.conf setenvif.load status.conf

rewrite.load 可能会导致重定向问题吗?有什么建议?

may rewrite.load cause redirection problem? Any suggestions?

推荐答案

我认为这种行为可能是预期的.

I would say the behaviour is probably expected.

当时 URL 的挂载点是 /bridge,这就是您在 URL 路径中使用的内容.这被翻译成:

The mount point for then URL is /bridge and that is what you are using in the path for the URL. This gets translated to:

SCRIPT_NAME=/bridge
PATH_INFO=

传递给 Flask 时.通过路由的设置方式,Flask 期待看到:

when passed to Flask. With the way the route is set up, Flask is expecting to see:

SCRIPT_NAME=/bridge
PATH_INFO=/

因此,Flask 强制重定向以强制浏览器添加尾部斜杠.

as a result, Flask forces a redirection to force the browser to add a trailing slash.

问题是您的处理程序只需要 POST 并且通常重定向将始终导致后续请求为 GET 导致找不到处理程序,因为您的处理程序只接受 POST.

The problem is that your handler only expects POST and usually a redirection will always result in the subsequent request being a GET which results in no handler then being found because your handler only accepts POST.

简而言之,在可能成为自动尾随斜杠重定向主题的路由上使用 POST 处理程序是一个坏主意.在这种情况下,当挂载点是子 URL 时,当您在 WSGI 应用程序的挂载处拥有处理程序时,就会发生这种情况.

In short, it is a bad idea to have a POST handler on a route which can be the subject of automatic trailing slash redirection. In this case this is happening as you have the handler at the mount of the WSGI application when the mount point is a sub URL.

要测试处理程序是否有效,请在您的浏览器中使用 /bridge/ 而不是 /bridge 在您的 URL 中.最好还是将 POST 处理程序移动到 WSGI 应用程序的挂载点以外的其他路径.

To test though that the handler worked, in your browser, use /bridge/ in your URL instead of /bridge. Better still move your POST handler to a different route other than the mount point for the WSGI application.

至于其他奇怪的 Apache 错误,您有时会在使用安全连接时由于错误而导致连接被拉断.

As to the other strange Apache errors, you can get that sometimes when connections are pulled down due to errors when secure connections are used.

这篇关于wsgi 错误:无法为请求和请求获取桶旅apache2 重定向帖子以获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆