Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111899 > unrolled thread

Re: Possible to capture cgitb style output in a try/except section?

Started byMalcolm Greene <python@bdurham.com>
First post2016-07-26 11:52 -0400
Last post2016-07-26 11:52 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Possible to capture cgitb style output in a try/except section? Malcolm Greene <python@bdurham.com> - 2016-07-26 11:52 -0400

#111899 — Re: Possible to capture cgitb style output in a try/except section?

FromMalcolm Greene <python@bdurham.com>
Date2016-07-26 11:52 -0400
SubjectRe: Possible to capture cgitb style output in a try/except section?
Message-ID<mailman.131.1469548376.22221.python-list@python.org>
Hi Steven and Peter,

Steven: Interestingly (oddly???) enough, the output captured by hooking
the cgitb handler on my system appears to be shorter than the default
cgitb output. You can see this yourself via this tiny script:

import cgitb
cgitb.enable(format='text')
x = 1/0

The solution I came up with (Python 3.5.1) was to use your StringIO
technique with the Hook's 'file=' parameter.

import io

cgitb_buffer = io.StringIO()
cgitb.Hook(file=cgitb_buffer, format='text)
return cgitb_buffer.getvalue()

Peter:  Your output was helpful in seeing the difference I mentioned
above.

Thank you both for your help!

Malcolm

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web