python save cookies

Solutions on MaxInterview for python save cookies by the best coders in the world

showing results for - "python save cookies"
Jordan
19 Apr 2016
1import requests, pickle
2session = requests.session()
3# (Make some calls)
4
5# Save the cookies to file:
6with open('somefile', 'wb') as f:
7    pickle.dump(session.cookies, f)
8# __________________________________
9
10# Get the cookies from file:
11session = requests.session()  # or an existing session
12
13with open('somefile', 'rb') as f:
14    session.cookies.update(pickle.load(f))