使用flask的时候遇到的问题及其解答

在网上看到了mircoblog的这个web程序,用flask框架写的,自己就在windows的环境下实现了下。

1.这个博客系统用到了一个flask插件叫flask_Login 里面涉及到编码解码的问题 出错的提示是:

base = unicode("%s|%s" % (request.remote_addr,request.headers.get("User-Agent")), 'utf8', errors='replace')

TypeError: decoding Unicode is not supported

查阅了下stackoverflow http://stackoverflow.com/questions/7634715/python-decoding-unicode-is-not-supported

原因写的很清楚,可能是"%s|%s" % (request.remote_addr,request.headers.get("User-Agent")),本身已经是unicode了,没必要用utf-8进行解码

这个unicode的意思相当于 参数1.decode('utf-8') 得到的应该是unicode 但是若参数1本身已经是unicode的话 就没必要解码了。

解决方法就是

 

base = "%s|%s" % (request.remote_addr,request.headers.get("User-Agent"))

posted @ 2013-06-26 04:06  no13bus  阅读(478)  评论(0编辑  收藏  举报