最近用webpy开发web应用,不出所料刚开始果然遇到很多未知问题,这里总结一下。
调试模式下异常捕捉问题,在开发过程中我在操作数据库是老是遇到以下的这个问题(实际上所有异常都报这个错误...)
01 | File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.py" , line 305, in debugerror |
02 | return web._InternalError(djangoerror()) |
03 | File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.py" , line 295, in djangoerror |
04 | return t(exception_type, exception_value, frames) |
05 | File "D:\����\eclipesWork\python\PyTest\src\web\template.py" , line 881, in __call__ |
06 | return BaseTemplate.__call__(self, *a, **kw) |
07 | File "D:\����\eclipesWork\python\PyTest\src\web\template.py" , line 808, in __call__ |
08 | return self.t(*a, **kw) |
09 | File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.pyc" , line 153, in __template__ |
10 | <ul class= "traceback" > |
11 | File "D:\����\eclipesWork\python\PyTest\src\web\template.py" , line 825, in _escape |
12 | value = safeunicode(value) |
13 | File "D:\����\eclipesWork\python\PyTest\src\web\utils.py" , line 348, in safeunicode |
14 | return obj.decode(encoding) |
15 | File "C:\Python27\lib\encodings\utf_8.py" , line 16, in decode |
16 | return codecs.utf_8_decode(input, errors, True) |
17 | UnicodeDecodeError: 'utf8' codec can't decode byte 0xb9 in position 3: invalid start byte |
这样的问题让我很是纠结因为我根本看不到具体是什么问题。解决方式建一个超类捕获GET与POST的异常.
以后所有的操作类都继承这个超类并且实现对应的myGET和myPOST方法(不用GET和POST方法)
1 | class userreg(baseweb): |
这样出现异常以后可以直接在调试网页显示异常信息如下图