mod_wsgi sometimes gives error on first reload but not thereafter

232 views
Skip to first unread message

Chris Seberino

unread,
Jun 14, 2010, 12:48:29 PM6/14/10
to Django users
1. Restarting Apache+mod_wsgi
2. Clearing Firefox cache and
3. Visiting Django app URL

are all done often when debugging/developing a DJango app under Apache
+mod_wsgi.

I've noticed with mod_wsgi, I will *SOMETIMES* get an error after this
triad.

Reloading the Django URL makes it go away so it only appears on the
first visit to Django app.

I will see sometimes like "400 Bad Request" page in Firefox...

"""
Bad Request

Your browser sent a request that this server could not understand.
Request header field is missing ':' separator.

er.com/set_up
"""

The DJango URL (I'm using Django auth) is
https://seoconquer.com/sign_in?next=/set_up

Any help greatly appreciated.

cs

Graham Dumpleton

unread,
Jun 14, 2010, 8:02:02 PM6/14/10
to Django users


On Jun 15, 2:48 am, Chris Seberino <cseber...@gmail.com> wrote:
> 1. Restarting Apache+mod_wsgi
> 2. Clearing Firefox cache and
> 3. Visiting Django app URL
>
> are all done often when debugging/developing a DJango app under Apache
> +mod_wsgi.
>
> I've noticed with mod_wsgi, I will *SOMETIMES* get an error after this
> triad.
>
> Reloading the Django URL makes it go away so it only appears on the
> first visit to Django app.
>
> I will see sometimes like "400 Bad Request" page in Firefox...
>
> """
> Bad Request
>
> Your browser sent a request that this server could not understand.
> Request header field is missing ':' separator.
>
> er.com/set_up
> """
>
> The DJango URL (I'm using Django auth) ishttps://seoconquer.com/sign_in?next=/set_up
>
> Any help greatly appreciated.

Use WSGI script described in:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

Please let us know if this solves issue or not as still waiting for
confirmation that this helps solve that problem.

Graham

Chris Seberino

unread,
Jun 15, 2010, 10:45:32 AM6/15/10
to Django users
On Jun 14, 7:02 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
In mod_wsgi's defense, remember that this error happens sporadically
and is NOT a showstopper as a reload makes it go away completely
(until a future restart).

I did look at that page a while back when we talked previously. It
helped me get mod_wsgi working. I'm not sure what you are asking me
to do....Do you want me to use the exact script and send you the
output of the print statements? Would my aforementioned error show up
in the Apache logs? If and when I see it again I will look in the
Apache error.log for clues too.

cs

Chris Seberino

unread,
Jun 15, 2010, 7:16:42 PM6/15/10
to Django users
I found the Apache error for this mod_wsgi error that only appears the
first time I reload an app after restarting Apache....

[Tue Jun 15 18:12:39 2010] [error] [client <address removed>] request
failed: error reading the headers, referer: http://<domain removed>

Graham Dumpleton

unread,
Jun 15, 2010, 7:40:21 PM6/15/10
to Django users
At the end of the document it has the alternate WSGI script file
contents as shown below. Simply use that and change the path to match
where your site is.

import sys

sys.path.insert(0, '/usr/local/django/mysite')

import settings

import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')

command.validate()

import django.conf
import django.utils

django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Graham Dumpleton

unread,
Jun 15, 2010, 7:42:02 PM6/15/10
to Django users
That error from Apache would likely indicate the client browser or
otherwise sent malformed headers.

This occurs when Apache is first reading HTTP headers for request and
long before it hands it off to any Django application or even
mod_wsgi.

Graham

Chris Seberino

unread,
Jun 16, 2010, 10:07:47 AM6/16/10
to Django users
On Jun 15, 6:42 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

> This occurs when Apache is first reading HTTP headers for request and
> long before it hands it off to any Django application or even
> mod_wsgi.

Is there anything I can do about this? I assume this means we should
pronounce the mod_wsgi setup I have good and not bother trying to use
your sample script after all like you discussed in previous email?

cs

Matt Hoskins

unread,
Jun 16, 2010, 10:57:19 AM6/16/10
to Django users
Since it looks like a problem with the http communication between the
browser and the server you might find it worth hooking something like
TCPWatch (http://hathawaymix.org/Software/TCPWatch) in between the two
and look at what's going back and forth to try spot where the problem
is being introduced. On the face of it, it seems most likely it's your
copy of firefox misbehaving for some reason!

Matt
Reply all
Reply to author
Forward
0 new messages