Gracefully handle malformed cookiejars
LoadError would only be raised if the cookiejar didn't contain the expected magic header. But a pickeled jar would potentially contain data that raised a UnicodeDecodeError, so we need account for both.
This commit is contained in:
parent
721f2a0d69
commit
358d84e334
1 changed files with 7 additions and 3 deletions
|
@ -151,9 +151,12 @@ class PyiCloudService(object):
|
||||||
if os.path.exists(cookiejar_path):
|
if os.path.exists(cookiejar_path):
|
||||||
try:
|
try:
|
||||||
self.session.cookies.load()
|
self.session.cookies.load()
|
||||||
except cookielib.LoadError:
|
logger.debug("Read cookies from %s", cookiejar_path)
|
||||||
# Most likely a pickled cookiejar from earlier versions
|
except:
|
||||||
pass
|
# Most likely a pickled cookiejar from earlier versions.
|
||||||
|
# The cookiejar will get replaced with a valid one after
|
||||||
|
# successful authentication.
|
||||||
|
logger.warning("Failed to read cookiejar %s", cookiejar_path)
|
||||||
|
|
||||||
self.params = {
|
self.params = {
|
||||||
'clientBuildNumber': '14E45',
|
'clientBuildNumber': '14E45',
|
||||||
|
@ -191,6 +194,7 @@ class PyiCloudService(object):
|
||||||
if not os.path.exists(self._cookie_directory):
|
if not os.path.exists(self._cookie_directory):
|
||||||
os.mkdir(self._cookie_directory)
|
os.mkdir(self._cookie_directory)
|
||||||
self.session.cookies.save()
|
self.session.cookies.save()
|
||||||
|
logger.debug("Cookies saved to %s", self._get_cookiejar_path())
|
||||||
|
|
||||||
self.data = resp
|
self.data = resp
|
||||||
self.webservices = self.data['webservices']
|
self.webservices = self.data['webservices']
|
||||||
|
|
Loading…
Reference in a new issue