Closed discdiver closed 4 years ago
Thanks for testing it out!
The error at the very bottom is from Medium, stating that the "media is not in a format we understand". Looks like it loaded 17 images and then failed. The image must be png, jpeg, tiff, or gif if I recall correctly.
Maybe theres an image in your markdown thats not one of these formats?
Also, I just updated this package a few minutes ago, though it won't help with this error (I believe), but you might want to update regardless.
Also, can you upload the notebook here (attach it in a post).
And to answer your other question - this is just for the classic notebook. Jupyter Lab seems to have a completely different interface for adding extensions, though I haven't looked deeply, and if someone knew what they were doing, I'd imagine it wouldn't take too long.
Thanks.
Images are .jpg or .png. There are some emoji, but those should all be unicode characters. No image types I haven't used on Medium before.
I updated the package. As you expected, same result.
I tried switching from chrome to matplotlib for table conversions, in case that was the issue. Same result.
It could be helpful if the error message told me which image failed. Might be something worth adding to future releases.
Notebooks can't be attached to GitHub issues comments, apparently. Learn something every day. I'll link to a GitHub repo.
GitHub should have sent you an invite to collaborate for the repo, @tdpetrou
Re: JupyterLab, I wish I were a person who knew building extensions, but I don't yet.
Might be worth saying explicitly in the ReadMe that this is just for classic Jupyter Notebooks so folks know that.
jupter_to_medium appears to be trying to upload a bunch of images when it fails, but only the 4 files I created are in the ..._files folder. Images generated from the DataFrame html ouptput tables are not in that folder. I don't know if they are supposed to be there?
Attempting to answer all q's here:
..._files
folder since they are saved bytesCan you test out a really short notebook with maybe one markdown image and one dataframe?
EDIT - just downloaded the notebook and it failed for me a well.
I was able to upload a few short notebooks with all the same images I added to the other notebook. 🎉
Then I got a different error when I ran the script to upload after I added a sidetable method. I'll make a new issue for that as it appears unrelated to this one. Although, I wonder why I didn't get that error with my previous notebook. 🤔
I think I see two problems. One, I need to change the extension to 'jpeg' if its 'jpg' and two, the _files
directory must be deleted no matter what before the start. This is why you are getting different errors. the _files
directory still contains old images.
In _.publish_to_medium.load_images_to_medium add this line
if extension == 'jpg':
extension = 'jpeg'
and i think things will work. Make sure to delete the _files
directory. I'll have a fix for this soon.
Hold up. Making that change doesn't work, but changing the image extensions themselves to jpeg does. I'll have to make the change to jpeg earlier.
Hmm. Maybe I'm misunderstanding, but I tried deleting the files directory earlier several times to no avail.
For my short test cases with different issues I didn't delete the images folder and I repeatedly ran the script and it uploaded everything fine.
Also, when I looked at Medium's guide to images, it said it would take .jpg and .jpeg:
Note: The editor supports images up to 25MB in the .JPG, .JPEG, .GIF, and .PNG formats.
https://help.medium.com/hc/en-us/articles/215679797-Images
Maybe a dumb question, but where do I access _.publish_to_medium.load_images_to_medium
? I installed in a conda environment using pip.
The images upload as .jpg just fine in a brief example notebook.
That linked article is for posting not API. The API only uses JPEG - https://github.com/Medium/medium-api-docs
I've made the change in another place and am able to get the entire notebook to load
I'll have a fix for this soon and remove the creating of the _files
directory unless explicitly saving the markdown.
I made some changes to the notebook, deleted the image folder created by jtm. Some images seemt to load ok. Then I get a JSONDecodeError when trying to do table_conversion with matplotlib
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
loading image to medium
Traceback (most recent call last):
File "jtm_script.py", line 15, in <module>
table_conversion="matplotlib",
File "/Users/jeffhale/miniconda3/lib/python3.7/site-packages/jupyter_to_medium/_publish_to_medium.py", line 311, in publish
p.main()
File "/Users/jeffhale/miniconda3/lib/python3.7/site-packages/jupyter_to_medium/_publish_to_medium.py", line 231, in main
self.load_images_to_medium()
File "/Users/jeffhale/miniconda3/lib/python3.7/site-packages/jupyter_to_medium/_publish_to_medium.py", line 163, in load_images_to_medium
req_json = r.json()
File "/Users/jeffhale/miniconda3/lib/python3.7/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/Users/jeffhale/miniconda3/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Users/jeffhale/miniconda3/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/jeffhale/miniconda3/lib/python3.7/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)
Gotcha re: API jpg vs. jpeg. But that's strange because I included the same .jpg files just fine in a sample notebook and everything uploaded fine. I didn't rename them to .jpeg
Just released a new version with the updates. No files will be created locally, unless save markdown is chosen. jpg are sent to Medium as jpeg.
Can you upgrade to 0.1.1 and try again?
Thank you, Ted! Updated to 0.1.1 All good.
Thank you for making this. Trying it out.
Just installed. Restarted JupyterLab server. I don't see the deploy option there. Figuring maybe this is only for Jupyter notebook?
Tried to run from the command line. Got the following stack trace. Any advice?