I have the following code in a test wsgi application using mod_wsgi:
from mako.template import Template
from mako.lookup import TemplateLookup
import mako.exceptions
def application(environ, start_response):
try:
open('nosuchfile')
except:
status = '500 Internal Server Error'
output = mako.exceptions.html_error_template().render()
response_headers = [('Content-type', 'text/html')
('Content-length, str(len(output)))]
start_response(status, response_headers)
return [output]
This gives the following error in my apache log:
mod_wsgi (pid=12785): Exception occurred processing WSGI script
'/var/www/genomes/wsgi-bin/index.py'.
Traceback (most recent call last):
File "/var/www/genomes/wsgi-bin/index.py", line 7, in application
open('nosuchfile')
IOError: [Errno 2] No such file or directory: 'nosuchfile'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/www/genomes/wsgi-bin/index.py", line 10, in application
output = mako.exceptions.html_error_template().render()
File "/usr/lib64/python3.2/site-packages/mako/template.py", line 397, in
render
return runtime._render(self, self.callable_, args, data)
File "/usr/lib64/python3.2/site-packages/mako/runtime.py", line 765, in
_render
**_kwargs_for_callable(callable_, data))
File "/usr/lib64/python3.2/site-packages/mako/runtime.py", line 797, in
_render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/usr/lib64/python3.2/site-packages/mako/runtime.py", line 823, in
_exec_template
callable_(context, *args, **kwargs)
File "memory:0x7f56e86bd590", line 67, in render_body
TypeError: Type str doesn't support the buffer API
However, running the following from an interactive shell gives the expected
html output. Additionally, using text_error_template() works in both cases.
import mako.exceptions
try:
open('nosuchfile')
except:
output = mako.exceptions.html_error_template().render()
print(output.decode())
Does anybody know whether this means I have set something up incorrectly, or is
this a bug in mod_wsgi?
I am using mod_wsgi-3.3, mako-0.7.0, apache-2.2.22 on gentoo linux.
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/modwsgi/-/LZIxQtJZqqMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.