There is no immediate way to do so, but it's not hard to do.
You can get a CookieJar
object from the session as session.cookies
, you can use pickle
to store it to a file.
A full example:
import requests, pickle
session = requests.session()
# Make some calls
with open('somefile', 'wb') as f:
pickle.dump(session.cookies, f)
Loading is then:
session = requests.session() # or an existing session
with open('somefile', 'rb') as f:
session.cookies.update(pickle.load(f))
The requests library has uses the requests.cookies.RequestsCookieJar()
subclass, which explicitly supports pickling and a dict-like API, and you can use the RequestsCookieJar.update()
method to update an existing session cookie jar with those loaded from a pickle file.
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有