New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save and load session #2522
Comments
The easiest thing to do is just to pickle the whole import requests, requests.utils, pickle
session = requests.session()
# Make some calls
with open('somefile', 'w') as f:
pickle.dump(session, f) with open('somefile') as f:
session = pickle.load(f) |
As an addendum: looks like Python3 expects the 'b' flag during write and read: with open('somefile', 'wb') as f:
pickle.dump(session, f) with open('somefile', 'rb') as f:
session = pickle.load(f) |
I tried using this approach, however I could not get TLS session resumption to work after reloading the pickled session. Does anyone know how to achieve this behavior? |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'd like to be able to save and load a session to disk. I think this means just saving and loading the cookies, but perhaps there are other nuances that would need to be included.
I'm interested in using Robobrowser (https://github.com/jmcarp/robobrowser) which wraps requests. I'd like to be able to persist the browser between running my application, which means being able to save and load the session to disk.
There is a SO post regarding how to do this. I think tellingly, the most popular answer is wrong.
http://stackoverflow.com/questions/13030095/how-to-save-requests-python-cookies-to-a-file
Thanks,
Jim
The text was updated successfully, but these errors were encountered: