search

Home  >  Q&A  >  body text

python为什么不适用pickle来直接序列化requests.的session.cookies?

import requests
sess=requests.session()
resp=sess.get('http://www.so.com')
f=open('cookiefile','wb')
pickle.dump(resp.cookies,f)  #为什么很多代码都不是这样,而是使用cookielib的LWPCookieJar?
f.close()
PHP中文网PHP中文网2829 days ago751

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:21:55

    1. How do you restore it, use load ?

    2. After restoration, how do you operate cookies (add, delete, modify, check)

    3. The cookie after you load is just a string. There are no more abstract operations, and you have to write your own functions to implement it

    4. Cookie is an entity, so it is naturally suitable to use class to abstractly encapsulate it

    5. It’s not that you can’t use pickle, it’s a question of convenience or inconvenience

    6. It is a compromise choice after weighing the pros and cons of all aspects

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:21:55

    First of all, pickle is not safe and it is unique to Python. If you interact with other languages, it cannot be operated

    reply
    0
  • Cancelreply