Django:400错误的请求语法 - 这个消息是什么意思? [英] Django: 400 bad request syntax - what does this message mean?

查看:1247
本文介绍了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 \x8a \xc3 \x8a \xc3 \x99J)6\xfb\xc44\x00\x00H\xc0')

  2. ?? ñ???? Z'5'Y4 ?????Ť?? UJ)6·4H 2 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)
对于enr in admin_enrollment:
course = Course.objects.get(id = enr.getCourseId())
admin_courses.append(course)
if(len(admin_courses)> 0):
return HttpResponseRedirect('/ admin')
else:
return HttpResponseRedirect('/ home')
return HttpResponseRedire ct('/ login')


解决方案

问题是,如果您尝试通过https访问django服务器,则会发生这种情况。切换回http,该错误将消失。


I am using django to build a simple website. When you type the base address (which for now is 127.0.0.1:8000/), I use django to show a view which does some checks and redirects you based on your user privileges. (If you have admin privileges, you go to '/admin', if you don't you go to '/home', and if you aren't logged in you go to '/login'.)

When I make that HTTP request, I get redirected as I should but I also see the following two errors in my django log:

  1. code 400, message Bad request syntax ('\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 -

I translated the hex in the first one to be (spaces added for legibility): 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 &

I can certainly see why the server wouldn't like that as a request, but I have no idea where it's coming from.

Any ideas?

Thanks very much.

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

Here is the code for the view:

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 enr in admin_enrollment:
            course = Course.objects.get(id=enr.getCourseId())
            admin_courses.append(course)
        if (len(admin_courses)>0):
            return HttpResponseRedirect('/admin')
        else:
            return HttpResponseRedirect('/home')
    return HttpResponseRedirect('/login')

解决方案

To address your actual question, this occurs if you're trying to access the django server over https. Switch back to http and that error will disappear.

这篇关于Django:400错误的请求语法 - 这个消息是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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