Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: not a PNG file #63

Open
BexTuychiev opened this issue Jan 20, 2023 · 3 comments · May be fixed by #79
Open

SyntaxError: not a PNG file #63

BexTuychiev opened this issue Jan 20, 2023 · 3 comments · May be fixed by #79

Comments

@BexTuychiev
Copy link

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?

@mjam03
Copy link
Collaborator

mjam03 commented Apr 1, 2023

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

@FoamoftheSea
Copy link

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.
image

@FoamoftheSea
Copy link

@mjam03 Created PR #79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants