From c7ea1bc1c8b420c310e2ee8fb02aa114de5050d8 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Fri, 24 Dec 2021 10:50:40 +0000 Subject: [PATCH] fix error when trying to re-create media folder --- example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example.py b/example.py index 5efc94c..0ef06d4 100644 --- a/example.py +++ b/example.py @@ -118,7 +118,8 @@ def req(): photo_url = os.path.join(os.environ.get('MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg") # make directory if needed - os.makedirs(os.path.dirname(filename)) + if not os.path.exists(os.path.dirname(filename)): + os.makedirs(os.path.dirname(filename)) with open(filename, 'wb') as f: f.write(r.content)