jupyter_to_medium
jupyter_to_medium copied to clipboard
SyntaxError: not a PNG file
I can't push a notebook to Medium because of the following error:
Traceback (most recent call last):
File "\\wsl$\Ubuntu\home\bexgboost\articles\deploy_to_medium.py", line 4, in <module>
jtm.publish('2023/1_january/3_synthetic_data_generators/notebook.ipynb',
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\jupyter_to_medium\_publish_to_medium.py", line 300, in publish
p.main()
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\jupyter_to_medium\_publish_to_medium.py", line 218, in main
self.md, self.image_data_dict = self.create_markdown()
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\jupyter_to_medium\_publish_to_medium.py", line 121, in create_markdown
no_ex_pp.preprocess(self.nb, self.resources)
File "C:\Users\bex\anaconda3\envs\articles\lib\site-packages\nbconvert\preprocessors\base.py", line 69, in preprocess
nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\jupyter_to_medium\_preprocesors.py", line 148, in preprocess_cell
output['data'] = {'image/png': converter(html)}
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\jupyter_to_medium\_screenshot.py", line 169, in run
img = self.take_screenshot()
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\jupyter_to_medium\_screenshot.py", line 121, in take_screenshot
img = mimage.imread(buffer)
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\matplotlib\image.py", line 1560, in imread
with img_open(fname) as image:
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\PIL\ImageFile.py", line 116, in __init__
self._open()
File "C:\Users\bex\AppData\Roaming\Python\Python39\site-packages\PIL\PngImagePlugin.py", line 712, in _open
raise SyntaxError("not a PNG file")
SyntaxError: not a PNG file
What might be the reason for this? Plots (I do have some from Seaborn). The problem is only with that notebook, other notebooks are pushing fine. Here is a link to the notebook.
@tdpetrou, can you please take a look if you have time?
Hi there,
Sorry for not getting back to you sooner. I've actually seen that our tests are now failing only on windows with this issue. It seems to be due to:
- plots get screenshotted using Chrome
- that should produce a png
- the matplotlib.image module expects this and fails otherwise
I don't have a windows so can't test this and can't find anything around the web on it but will keep searching this week and try to get fixed.
Mark
I was having this problem in 0.2.13 on Windows. The subprocess call to chrome.exe to take the screenshot was creating an empty PNG image, but I was able to fix that by taking lines 115-126 out of the context manager block in _screenshot.py.
This made the image come out larger than 0KB, and fixes the downstream issue.
@mjam03 Created PR https://github.com/dexplo/jupyter_to_medium/pull/79