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

查看:125
本文介绍了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" 500860-"-"和错误日志: "[[Fri Dec 22 11:44:51.864122 2017] [wsgi:error] [pid 28906:tid 139849921148672](70008)部分结果有效,但处理不完整:[client 57.39.118.158:35172] mod_wsgi(pid = 28906) :无法请求要求的铲斗旅." 之前,在 404网址中出现了找不到网址"问题找不到apache2上烧瓶应用程序的错误.

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.1+编译的python 3.5.2,apache 2.4,OpenSSL/1.0.2g,ubuntu 16.04,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

/p/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

/p/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.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谈判.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.

要测试处理程序是否正常运行,请在您的浏览器中,在URL中使用/bridge/而不是/bridge.最好还是将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天全站免登陆