I have a problem trying to save cookies to a file using the FileCookieJar save method. Here is my code:
#!/usr/bin/python import httplib, cookielib, urllib2, json, time from datetime import date class FoN: def __init__(self): self.cookiefile = "cookies.txt" self.cj = cookielib.FileCookieJar(self.cookiefile) def login (self, login, password): js = json.JSONEncoder().encode({"login":login,"password":password}) req=urllib2.Request("http://www.example.com/user/login", js) res=urllib2.urlopen(req) self.cj.extract_cookies(res,req) self.cj.save(self.cookiefile, ignore_discard=True) f.write ("Login: "+login+", result: "+str(res.read().count("true"))+"\n") time.sleep(2) return res
Thus, it fails when calling self.cj.save(self.cookiefile, ignore_discard=True) raise NotImplementedError , which matches the documentation. But my question is, how do I save cookies to a file? I even tried to include the code in try , but that didn't help.
source share