wsgi error: Unable to get bucket brigade for request & apache2 redirects post to get?
wsgi error: Unable to get bucket brigade for request & apache2 redirects post to get?
我想使用部署在 apache2 上的 Flask 应用程序处理 post 请求,但我遇到了意外重定向。它还会丢失请求正文。
我使用 Web 应用程序触发 post 请求,访问日志显示:
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 "-" "-" 和错误日志:
“[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):无法获得请求的水桶旅。”
之前,处的问题"url not found"已经解决了。
我正在使用 python 3.5.2、apache 2.4、OpenSSL/1.0.2g、ubuntu 16.04、mod_wsgi4.3.0 为 [=81 编译=] 3.5.1+
我启用了一个独特的 conf 文件,它是这样的:
<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 的文件是
#!/usr/bin/python3
import sys
sys.path.insert(0,'/var/www/bridge')
from bridge import app as application
位于 /var/www/bridge/bridge.py 的文件是
#!/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 权限的用户。启用的模组是:
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导致重定向问题?有什么建议么?
我会说这种行为可能是预期的。
然后 URL 的安装点是 /bridge
,这就是您在 URL 的路径中使用的。这被翻译成:
SCRIPT_NAME=/bridge
PATH_INFO=
传递给 Flask 时。通过设置路由的方式,Flask 期望看到:
SCRIPT_NAME=/bridge
PATH_INFO=/
因此,Flask 强制重定向以强制浏览器添加尾部斜杠。
问题是您的处理程序只需要 POST
,通常重定向总是会导致后续请求成为 GET
,这会导致找不到处理程序,因为您的处理程序只接受 POST
.
简而言之,在可能成为自动尾部斜杠重定向主题的路由上使用 POST
处理程序是个坏主意。在这种情况下,当挂载点是子 URL.
时,您在 WSGI 应用程序的挂载处有处理程序,就会发生这种情况。
要测试处理程序是否有效,请在您的浏览器中,在 URL 中使用 /bridge/
而不是 /bridge
。最好还是将您的 POST
处理程序移动到不同于 WSGI 应用程序挂载点的其他路径。
至于其他奇怪的 Apache 错误,您有时会在使用安全连接时由于错误导致连接断开时遇到这种情况。
我想使用部署在 apache2 上的 Flask 应用程序处理 post 请求,但我遇到了意外重定向。它还会丢失请求正文。
我使用 Web 应用程序触发 post 请求,访问日志显示:
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 "-" "-" 和错误日志:
“[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):无法获得请求的水桶旅。”
之前,
我正在使用 python 3.5.2、apache 2.4、OpenSSL/1.0.2g、ubuntu 16.04、mod_wsgi4.3.0 为 [=81 编译=] 3.5.1+
我启用了一个独特的 conf 文件,它是这样的:
<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 的文件是
#!/usr/bin/python3
import sys
sys.path.insert(0,'/var/www/bridge')
from bridge import app as application
位于 /var/www/bridge/bridge.py 的文件是
#!/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 权限的用户。启用的模组是:
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导致重定向问题?有什么建议么?
我会说这种行为可能是预期的。
然后 URL 的安装点是 /bridge
,这就是您在 URL 的路径中使用的。这被翻译成:
SCRIPT_NAME=/bridge
PATH_INFO=
传递给 Flask 时。通过设置路由的方式,Flask 期望看到:
SCRIPT_NAME=/bridge
PATH_INFO=/
因此,Flask 强制重定向以强制浏览器添加尾部斜杠。
问题是您的处理程序只需要 POST
,通常重定向总是会导致后续请求成为 GET
,这会导致找不到处理程序,因为您的处理程序只接受 POST
.
简而言之,在可能成为自动尾部斜杠重定向主题的路由上使用 POST
处理程序是个坏主意。在这种情况下,当挂载点是子 URL.
要测试处理程序是否有效,请在您的浏览器中,在 URL 中使用 /bridge/
而不是 /bridge
。最好还是将您的 POST
处理程序移动到不同于 WSGI 应用程序挂载点的其他路径。
至于其他奇怪的 Apache 错误,您有时会在使用安全连接时由于错误导致连接断开时遇到这种情况。