V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
vtoexsir
V2EX  ›  Python

Python 为什么不使用 pickle 来直接序列化 requests.的 session.cookies 而常用 cookielib.LWPCookieJar 呢?

  •  
  •   vtoexsir · 2017-02-18 13:11:46 +08:00 · 3282 次点击
    这是一个创建于 2628 天前的主题,其中的信息可能已经有所发展或是发生改变。
    sess=requests.session()
    resp=sess.get('http://www.so.com')
    f=open('cookiefile','wb')
    pickle.dump(resp.cookies,f)  #为什么很多代码都不是这样,而是使用 cookielib 的 LWPCookieJar?
    f.close()```
    
    5 条回复    2017-02-18 16:06:38 +08:00
    013231
        1
    013231  
       2017-02-18 13:35:05 +08:00   ❤️ 1
    Warning The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.
    gouchaoer
        2
    gouchaoer  
       2017-02-18 13:37:40 +08:00 via Android   ❤️ 1
    这么说吧,除了 json 反序列化。。。。别的二进制的 /语言特性相关的,都不太安全
    phrack
        3
    phrack  
       2017-02-18 15:21:39 +08:00 via Android
    读文档不仔细了吧(๑`・ᴗ・´๑)
    skydiver
        4
    skydiver  
       2017-02-18 15:38:55 +08:00 via Android   ❤️ 1
    cookie 属于用户输入数据
    反序列化用户输入数据不安全
    vtoexsir
        5
    vtoexsir  
    OP
       2017-02-18 16:06:38 +08:00
    感谢各位热情回复!
    原来如此.
    英文读懂了 4 分!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2213 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 02:11 · PVG 10:11 · LAX 19:11 · JFK 22:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.