On 10 October 2012 05:37, Daniel Norton <
dano...@gmail.com> wrote:
> There's probably a shorter path to my solution, so here's some background:
>
> I'm no Python expert, but neither is the creator of the app, and I
> understand it better than he does.
> Somebody switched the app from a CENTOS server running Python 2.6 to an
> Ubuntu server running Python 2.7
> App crashes on new server
> Error log doesn't show where the error is, only this:
>
> mod_wsgi (pid=21820): Exception occurred processing WSGI script
> '/var/www/.../myscript'.
> TypeError: expected byte string object for header value, value of type
> unicode found
This is because your WSGI application is returning a response header
where the value is a Unicode string. All response header values must
be normal byte strings.
In mod_wsgi 3.X, the validation is potentially only done at the time
headers are being flushed I think so lost context. In mod_wsgi 4.X I
may from memory be validating when start_response() called and
throwing an error back to the application. Can't remember right now.
> I think I can use log_exception(), but I need the instance of the handler to
> hook it
Don't think that will help. May need a WSGI middleware wrapper which
provides a start_response() which validates headers and raises an
exception immediately.
> I surmise that mod_wsgi is acting as if it's creating an instance of the
> server, then calling handlerInstance.run(myapp)
If I understand what you are saying, no. It only makes use of the
'application' object and calls it for each request. There is no
calling of any mainloop by way of a run() function provided by your
application or framework.
> Is there an easier way to extract line number information out of the server?
> (currently: LogLevel info)
> Else, is there a better way to get the stack trace other than hooking
> log_exception?
> Else, what's a better way to hook log_exception?
> Else, how do I grab the instance of the handler class?
Anyway, just saw your response, but will send this anyway.
Graham