dexplo / jupyter_to_medium

Python package for publishing Jupyter Notebooks as Medium blogposts
https://dexplo.org/jupyter_to_medium
MIT License
147 stars 14 forks source link

Failed to post to Medium #40

Closed falahfakhri-Iraq closed 2 years ago

falahfakhri-Iraq commented 2 years ago

Returned error message below

"ValueError: Problem with posting: ])}while(1);{\"success\":false,\"error\":\"request entity too large\",\"v\":3,\"b\":\"20211123-1931-root\"}

Traceback (most recent call last): File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_to_medium\_publish_to_medium.py\", line 295, in publish_to_medium self.result = req.json() File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py\", line 910, in json return complexjson.loads(self.text, **kwargs) File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\json\init.py\", line 346, in loads return _default_decoder.decode(s) File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\json\decoder.py\", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\json\decoder.py\", line 355, in raw_decode raise JSONDecodeError(\"Expecting value\", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_to_medium\_bundler.py\", line 61, in upload data = publish(**kwargs) File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_to_medium\_publish_to_medium.py\", line 449, in publish p.main() File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_to_medium\_publish_to_medium.py\", line 331, in main self.publish_to_medium() File \"C:\Users\FALAH FAKHRI\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_to_medium\_publish_to_medium.py\", line 297, in publish_to_medium raise ValueError(\"Problem with posting:\n\" + req.text) ValueError: Problem with posting: ])}while(1);{\"success\":false,\"error\":\"request entity too large\",\"v\":3,\"b\":\"20211123-1931-root\"} "

mjam03 commented 2 years ago

Hi Falah,

Thanks for raising the issue. It looks like the problem isn't necessarily with the package but that the medium api is returning the 413 response:

"request entity too large"

which seems like a common api issue when you try to upload a large file. Can you:

Once I have the notebook I can set up a fresh environment and test to see if I can replicate the error. If so, I will look into finding a way to reduce the file size so that the Medium API will accept your publication. At first glance I'm not sure how to do this as all images/tables are already only passed by reference (they are uploaded separately to Medium).

falahfakhri-Iraq commented 2 years ago

Dear @mjam03 Thanks a lot for your reply, following is the link tot the notebook within my Github,

https://github.com/falahfakhri-Iraq/United-Kingdom-traffic-accidents-analysis-2020/blob/7cfa50945542fed3814a89a82d76a8264c78cf74/United%20Kingdom%20Road%20traffic%20accidents%20analysis-2020.ipynb

As a solution comes to my mind now, I think for the big size it's possible to create an image for the whole notebook, and post to Medium, but I also haven't a clue of how to do so.

mjam03 commented 2 years ago

Okay great. I've just replicated and got a timeout error back from the Medium API. This is because of the notebook's size even after stripping out all the images and tables and passing them by ref.

On inspection it seems like the notebook itself is not actually an 'article' but has lots of print statements outputting lists of variable names. I don't understand why that is making the markdown version so large but nevertheless this isn't really the intention of the package. The aim is to streamline publication of articles written in jupyter notebooks to Medium, not taking any given notebook (not written as an article) and find a way to put it into Medium.

Will close the issue but: