相关疑难解决方法(0)

Django:400错误的请求语法 - 这个消息是什么意思?

我正在使用django来构建一个简单的网站.当您键入基地址(现在是127.0.0.1:8000/)时,我使用django显示一个视图,该视图会执行一些检查并根据您的用户权限重定向您.(如果你有管理员权限,你去/admin,如果你不去/home,如果你没有登录,你去/login.)

当我发出HTTP请求时,我会被重定向,但我也会在django日志中看到以下两个错误:

  1. 代码400,消息错误的请求语法 ('\x16\x03\x01\x00\x95\x01\x00\x00\x91\x03\x01N\xaa\x9c\x08\x96\x7f\x92\xe9Z\x925\xcaY4\xa6\xa5\xab\xf2\x16\xfaT\x89\xe7\x8a\xc3\x99J)6\xfb\xc44\x00\x00H\xc0')
  2. "??N????Z?5?Y4?????T??ÙJ)6??4H?" 400 -

我将第一个中的十六进制翻译为(为了易读性添加了空格): SYN ETX NUL NUL U SOH NUL NUL Q ETX NUL N 170 156 X r 246 STX 141 214 ? 143 EOT FS j 142 223 s 241 220 < 185 \ \ m 242 &

我当然可以看到为什么服务器不喜欢这个请求,但我不知道它来自哪里.

有任何想法吗?

非常感谢.

==============

以下是视图的代码:

def index(request):
    user = request.user
    admin_courses = []

    if (user.is_authenticated()):
        u_id = user.getUserId()
        my_enrollment = Enrollment.objects.filter(user_id=u_id)
        admin_enrollment = my_enrollment.filter(type="ADMIN")
        for …
Run Code Online (Sandbox Code Playgroud)

django hex ascii http http-status-code-400

54
推荐指数
2
解决办法
4万
查看次数

基于SSL的虚拟主机,带有django和mod_wsgi

我有一个django Web应用程序,其中允许通过http访问某些URL,而其他URL只能通过http-secure访问.我需要在我的apache conf文件中设置virtualHost/mod_wsgi配置,以便可以通过两者访问同一个Web应用程序.我跟着这2个帖子

并且具有以下配置,我认为应该这样做.

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin me@mail.com
    DocumentRoot /var/www/html
    ServerName www.mydomain.com

    ErrorLog server-logs/error_log
    CustomLog server-logs/access_log common

    WSGIScriptAlias /test /var/www/my_app_root/apache/django.wsgi

    <Directory /var/www/my_app_root>
      Order allow,deny
      Allow from all
    </Directory>    
</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /etc/httpd/conf/ssl/mykey.crt
    SSLCertificateKeyFile /etc/httpd/conf/ssl/mykey.key

    ServerAdmin me@mail.com
    DocumentRoot /var/www/html
    ServerName www.mydomain.com

    ErrorLog server-logs/error_log
    CustomLog server-logs/access_log common

    WSGIScriptAlias /test /var/www/my_app_root/apache/django.wsgi

    <Directory /var/www/my_app_root>
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

但是,必须通过http访问的URL正在被访问而没有任何问题,而那些必须通过https的URL正在获得404 - 未找到错误.我有一个装饰器,可以查看是否通过http访问视图,然后重定向到URL,其中http替换为https.所以url-mapping是正确的,因为我看到重定向发生(这意味着视图被调用)但是通过https,它得到404错误.

我在webserver文档根目录中有第三方php应用程序,/var/www/html/它可以在https上正常工作.不知何故,该应用程序没有遇到任何关于http或https的问题.

我尝试了以下内容

  • 尝试WSGIProcessGroup在两个虚拟主机中使用相同名称的守护进程模式方法,但这也没有用.
  • 我尝试添加Listen 443命令,而apache抱怨端口已绑定错误.

编辑:

由于你的所有评论,我更多地探讨了配置,发现有一个子conf文件在运行时被拉入,它定义了*:443虚拟主机(并且没有wsgiscript指令).这就是为什么 …

apache django https mod-wsgi

5
推荐指数
1
解决办法
7560
查看次数

标签 统计

django ×2

apache ×1

ascii ×1

hex ×1

http ×1

http-status-code-400 ×1

https ×1

mod-wsgi ×1