I'm running the following WSGI app under Yaro:
def error(req):
try:
req.non_existent_key
except:
try:
return cgitb.html(sys.exc_info())
except:
return 'foo'
The result of running this is 'foo'. In other words, the reference to
the non-existent key generates an exception as expected, but then the
generation of the traceback generates ANOTHER exception, which I would
not have expected. If I add another TRY/EXCEPT block to capture this
exception, the result is attached at the bottom of this message.
It gets better.
I get the same result whether I run under Apache/mod_wsgi or standalone
using wsgi_ref. But if I add the following code to try to capture a
Yaro request object so I can noodle around with it:
def error(req):
global req1
req1=req
try: ...
it makes the problem go away! But it ONLY makes the problem go away
when running under wsgi_ref, not under Apache!
The problem seems to be specific to Yaro. If I make an instance of an
object and try to dereference a non-existent attribute, the initial
traceback gets generated with no problem. Also, the Yaro code for
Request.__getattr__ ultimately calls req.__dict__[attr]. If I make this
call directly, the problem also goes away.
I am quite baffled by this. Any suggestions on how to debug this would
be much appreciated.
Thanks,
rg
Python 2.5: /usr/local/bin/python
Mon Feb 2 00:54:33 2009
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
/www/sites/mcia.cc/files/wsgi/test.wsgi in error(req=)
212 except:
213 try:
214 return cgitb.text(sys.exc_info())
215 except:
216 try:
global cgitb =
cgitb.text =
global sys =
sys.exc_info =
/www/sites/cgitb.py in text((etype=,
evalue=KeyError('non_existent_key',), etb=), context=5)
215 try: return linecache.getline(file, lnum[0])
216 finally: lnum[0] += 1
217 vars = scanvars(reader, frame, locals)
218
219 rows = [' %s %s' % (file, call)]
builtinvars =
global scanvars =
reader =
frame =
locals = {'req': }
/www/sites/cgitb.py in scanvars(reader=, frame=, locals={'req':
})
82 if lasttoken == '.':
83 if parent is not __UNDEF__:
84 value = getattr(parent, token, __UNDEF__)
85 vars.append((prefix + token, prefix, value))
86 else:
value =
builtingetattr =
parent =
token = 'non_existent_key'
__UNDEF__ undefined
/www/sites/mcia.cc/files/wsgi/yaro.py in __getattr__(self=, attr='non_existent_key')
215 elif attr == 'cookie' and not 'cookie' in self.__dict__:
216 self._load_cookie()
217 return self.__dict__[attr]
218
219 def _parse_query(self):
self =
self.__dict__ = {'_start_response': , 'content_length': '',
'content_type': '', 'environ': {'DOCUMENT_ROOT':
'/www/sites/mcia.cc/html', 'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_ACCEPT':
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plai
n;q=0.8,image/png,*/*;q=0.5', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'en-us', 'HTTP_CACHE_CONTROL': 'max-age=0',
'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'sid=55UGS64T',
'HTTP_HOST': 'mcia.cc', 'HTTP_REFERER': 'http://mcia.cc/wtest/menu',
...}, 'exc_info': None, 'extra_props': None, 'method': 'GET', 'query':
{}, 'res': ,
'start_response_called': False, ...}
attr = 'non_existent_key'
: 'non_existent_key'
The above is a description of an error in a Python program. Here is
the original traceback:
Traceback (most recent call last):
File "/www/sites/mcia.cc/files/wsgi/test.wsgi", line 214, in error
return cgitb.text(sys.exc_info())
File "cgitb.py", line 217, in text
vars = scanvars(reader, frame, locals)
File "cgitb.py", line 84, in scanvars
value = getattr(parent, token, __UNDEF__)
File "/www/sites/mcia.cc/files/wsgi/yaro.py", line 217, in __getattr__
return self.__dict__[attr]
KeyError: 'non_existent_key'
--
http://mail.python.org/mailman/listinfo/python-list