I have a problem while trying to save cookies to a file using FileCookieJar
's 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
So it fails at self.cj.save(self.cookiefile, ignore_discard=True)
raising NotImplementedError
exception, which is according to the documentation. But my question how do I save cookies to the file then? I even tried to include the code in try
clause but that didn't help at all.
The base FileCookieJar
does not implement .save
To get saving, you should use one of the subclasses like MozillaCookieJar
or LWPCookieJar
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With