Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

http - Django: 400 bad request syntax - what does this message mean?

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 ('x16x03x01x00x95x01x00x00x91x03x01Nxaax9cx08x96x7fx92xe9Zx925xcaY4xa6xa5xabxf2x16xfaTx89xe7x8axc3x99J)6xfbxc44x00x00Hxc0')
  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')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...