推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dddd
V2EX  ›  Python

我又回来了,tornado 中文 cookie 乱码如何解决??

  •  
  •   dddd · May 27, 2014 · 5284 views
    This topic created in 4376 days ago, the information mentioned may be changed or developed.
    RT,照顾照顾,我毫无经验,遇到问题紧张得要死……
    9 replies    2014-05-29 10:07:49 +08:00
    Keyes
        1
    Keyes  
       May 27, 2014 via iPhone   ❤️ 1
    我保存的是什么?
    我读出来的是什么?
    我显示的是什么?

    里头都是坑,建议楼主研究一下字符编码的问题
    maga
        2
    maga  
       May 27, 2014
    建用 print repr(str) 打印出来看是utf-8还是unicode
    dddd
        3
    dddd  
    OP
       May 27, 2014   ❤️ 1
    @maga 'ç\x82¹ç\x82¹æ»´æ»´'这是什么编码???
    dddd
        4
    dddd  
    OP
       May 27, 2014
    @maga 点点滴滴 网页 [utf-8] 上这样显示
    yyfearth
        5
    yyfearth  
       May 27, 2014
    cookie 里面为啥要存中文? cookie 存一个Session ID不就可以了么, 其他东西存在Session里面?
    没用过tornado, 不过做其他系统的时候从来不往cookie里面存太多东西
    yemoluo
        6
    yemoluo  
       May 27, 2014
    先base64encode 然后放到cookie
    b1074549
        7
    b1074549  
       May 27, 2014 via Android
    看tornado源码,主动做encode decode。严格来说header里只允许ASCII字符
    maga
        8
    maga  
       May 27, 2014
    @dddd \x82\x81之类utf-8, \u5152之类才是unicode。主动做encode, decode吧
    geew
        9
    geew  
       May 29, 2014
    找一个tornado的session或者自己写一个session吧 cookie别存中文
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1014 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 21:58 · PVG 05:58 · LAX 14:58 · JFK 17:58
    ♥ Do have faith in what you're doing.