From 2298fa25a905be24e417eb3033a3ff94ff9b0d84 Mon Sep 17 00:00:00 2001 From: Chris Arthurs Date: Thu, 10 Oct 2019 17:01:34 +0100 Subject: [PATCH] Fix for #1809 Python 2.7 incompatibility in the iframe renderer --- packages/python/plotly/codegen/utils.py | 7 ++++++- packages/python/plotly/plotly/io/_base_renderers.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/codegen/utils.py b/packages/python/plotly/codegen/utils.py index f60be8391ee..0ba9c5e4cc2 100644 --- a/packages/python/plotly/codegen/utils.py +++ b/packages/python/plotly/codegen/utils.py @@ -6,6 +6,7 @@ from io import StringIO from typing import List import re +import errno # Source code utilities @@ -30,7 +31,11 @@ def write_source_py(py_source, filepath, leading_newlines=0): # Make dir if needed # ------------------ filedir = opath.dirname(filepath) - os.makedirs(filedir, exist_ok=True) + try: + os.makedirs(filedir) + except OSError as error: + if error.errno != errno.EEXIST: + raise # Write file # ---------- diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 64760d4728a..707348178e6 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -4,6 +4,7 @@ import webbrowser import inspect import os +import errno import six from plotly.io import to_json, to_image, write_image, write_html @@ -564,7 +565,11 @@ def to_mimebundle(self, fig_dict): filename = self.build_filename() # Make directory for - os.makedirs(self.html_directory, exist_ok=True) + try: + os.makedirs(self.html_directory) + except OSError as error: + if error.errno != errno.EEXIST: + raise write_html( fig_dict,