使用flask的时候遇到的问题及其解答
生活随笔
收集整理的這篇文章主要介紹了
使用flask的时候遇到的问题及其解答
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在網(wǎng)上看到了mircoblog的這個web程序,用flask框架寫的,自己就在windows的環(huán)境下實現(xiàn)了下。
1.這個博客系統(tǒng)用到了一個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
原因?qū)懙暮芮宄?#xff0c;可能是"%s|%s" % (request.remote_addr,request.headers.get("User-Agent")),本身已經(jīng)是unicode了,沒必要用utf-8進行解碼
這個unicode的意思相當于 參數(shù)1.decode('utf-8') 得到的應(yīng)該是unicode 但是若參數(shù)1本身已經(jīng)是unicode的話 就沒必要解碼了。
解決方法就是
?
base = "%s|%s" % (request.remote_addr,request.headers.get("User-Agent"))
轉(zhuǎn)載于:https://www.cnblogs.com/no13bus/p/3155911.html
總結(jié)
以上是生活随笔為你收集整理的使用flask的时候遇到的问题及其解答的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SharePoint场管理-PowerS
- 下一篇: windows下 apache 二级域名