From 6a3b05762e881712a4cd2194167e06161a9d8cda Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Sat, 27 Jul 2019 21:08:29 +0200 Subject: [PATCH] Fix missing directory error in some rare cases --- instaloader/instaloader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index 3a00d91..79fbe02 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -246,6 +246,7 @@ class Instaloader: filename += '.json.xz' else: filename += '.json' + os.makedirs(os.path.dirname(filename), exist_ok=True) save_structure_to_file(structure, filename) if isinstance(structure, (Post, StoryItem)): # log 'json ' message when saving Post or StoryItem @@ -374,6 +375,7 @@ class Instaloader: os.path.getsize(filename) >= int(content_length))): self.context.log(filename + ' already exists') return None + os.makedirs(os.path.dirname(filename), exist_ok=True) self.context.write_raw(profile_pic_bytes if profile_pic_bytes else profile_pic_response, filename) if date_object: os.utime(filename, (datetime.now().timestamp(), date_object.timestamp()))