webpy开发笔记01-调试模式下异常捕捉问题

  最近用webpy开发web应用,不出所料刚开始果然遇到很多未知问题,这里总结一下。

  调试模式下异常捕捉问题,在开发过程中我在操作数据库是老是遇到以下的这个问题(实际上所有异常都报这个错误...)

File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.py", line 305, in debugerror
    return web._InternalError(djangoerror())
  File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.py", line 295, in djangoerror
    return t(exception_type, exception_value, frames)
  File "D:\����\eclipesWork\python\PyTest\src\web\template.py", line 881, in __call__
    return BaseTemplate.__call__(self, *a, **kw)
  File "D:\����\eclipesWork\python\PyTest\src\web\template.py", line 808, in __call__
    return self.t(*a, **kw)
  File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.pyc", line 153, in __template__
    <ul class="traceback">
  File "D:\����\eclipesWork\python\PyTest\src\web\template.py", line 825, in _escape
    value = safeunicode(value)
  File "D:\����\eclipesWork\python\PyTest\src\web\utils.py", line 348, in safeunicode
    return obj.decode(encoding)
  File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb9 in position 3: invalid start byte
这样的问题让我很是纠结因为我根本看不到具体是什么问题。解决方式建一个超类捕获GET与POST的异常.

# -*- coding: utf-8 -*-
'''
Created on 2013-11-19

@author: 梁前武 QQ:1587790525
'''
class baseweb():
    def myGET(self):
        return "baseweb get"
    def myPOST(self):
        return "baseweb post" 
    def GET(self):
        v=""
        try:
            v=self.myGET()
        except Exception,e:
            return "erro %s"%(e)
        return v
    def POST(self):
        v=""
        try:
            v=self.myPOST()
        except Exception,e:
            return "erro %s"%(e)
        return v
以后所有的操作类都继承这个超类并且实现对应的myGET和myPOST方法(不用GET和POST方法)

class userreg(baseweb):
    def myGET(self):
        ...
这样出现异常以后可以直接在调试网页显示异常信息如下图


转载于:https://my.oschina.net/u/138488/blog/177477

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值