diff --git a/td/client.py b/td/client.py index 087f9dc..37a46f0 100644 --- a/td/client.py +++ b/td/client.py @@ -219,7 +219,15 @@ def _state_manager(self, action: str) -> None: self.state.update(json.load(json_file)) # if they want to save it and have allowed for caching then load the file. - elif action == 'save': + elif action == 'save': + # Create parent directory if it doesn't exist + if not credentials_file_exists: + try: + os.makedirs(os.path.dirname(self.credentials_path)) + except OSError as exc: # Guard against race condition + if exc.errno != errno.EEXIST: + raise + # Save file with open(file=self.credentials_path, mode='w+') as json_file: json.dump(obj=self.state, fp=json_file, indent=4)