How to save cookie to a file in Python?

Wrote a script to save cookies in a file to work with steam,but for some reason writes an error:
# coding: cp1251

import pickle
import steam.webauth as wa
session = wa.requests.session()
user = wa.WebAuth('LOGIN', 'PASSWORD')

try:
 with open('bcc.txt','r') as f:
 cookies = wa.requests.utils.cookiejar_from_dict(pickle.load(f))
 session = wa.requests.session(cookies=cookies)
user.login()
except wa.TwoFactorCodeRequired:
 print 'Enter a code for SteamGuard'
SGCode=raw_input()
user.login(twofactor_code=SGCode)
 with open('bcc.txt', 'w') as f:
 pickle.dump(wa.requests.utils.dict_from_cookiejar(wa.requests.session.cookies), f)
June 5th 19 at 21:23

Find more questions by tags HTTP CookiesPythonSteam