diff --git a/packages/python/plotly/codegen/utils.py b/packages/python/plotly/codegen/utils.py index 5bfd46830ca..ff950d60117 100644 --- a/packages/python/plotly/codegen/utils.py +++ b/packages/python/plotly/codegen/utils.py @@ -31,11 +31,9 @@ def write_source_py(py_source, filepath, leading_newlines=0): # Make dir if needed # ------------------ filedir = opath.dirname(filepath) - try: - os.makedirs(filedir) - except OSError as error: - if error.errno != errno.EEXIST: - raise + # The exist_ok kwarg is only supported with Python 3, but that's ok since + # codegen is only supported with Python 3 anyway + os.makedirs(filedir, exist_ok=True) # Write file # ---------- diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 707348178e6..f0642c7a3f5 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -4,7 +4,7 @@ import webbrowser import inspect import os -import errno +from os.path import isdir import six from plotly.io import to_json, to_image, write_image, write_html @@ -568,7 +568,7 @@ def to_mimebundle(self, fig_dict): try: os.makedirs(self.html_directory) except OSError as error: - if error.errno != errno.EEXIST: + if not isdir(self.html_directory): raise write_html(