Interaction with mkdocs-material, images produces by Social plugin cause error
holgerflick opened this issue Β· 19 comments
When using the social
plugin in conjunction with the RSS plugin, I get a huge amount of these errors.
WARNING:root:Remote image could not been reached: http://127.0.0.1:8000/assets/images/social/blog/posts/14-results.png. Trying again with GET and disabling SSL verification. Attempt: 1. Trace: <urlopen error [Errno 61] Connection refused> WARNING:root:Remote image could not been reached: http://127.0.0.1:8000/assets/images/social/blog/posts/14-results.png. Trying again with GET and disabling SSL verification. Attempt: 2. Trace: <urlopen error [Errno 61] Connection refused>
The author of Material for MkDocs analyzed the following @squidfunk :
The RSS plugin fetches the image and that seems to run into an error with SSL. Please report this upstream.
Hitting this as well
To help debug this, I created a minimal reproduction following the Material for MkDocs process. Hope this helps.
9.5.19-social-cards-images.zip
Run mkdocs serve
or remove the info plugin and mkdocs build
to reproduce.
Hi there,
Is the issue the same in community and insiders edition?
The reproduction was done with the public version but I am getting the same error message with 9.5.26+insiders.4.53.11. For the sheer fun of it, I also tested with public version 9.5.26 and getting the same.
Thanks you for having fun cases testing. It's a pretty tricky bug but I've got a lead to the guilty!
In the meantime, downgrading to 1.6.0 solved the issue for me. I'm not sure in which version this issue was introduced π
@alexvoss in fact your example can't work out of the box since the plugin tries to read image length (required for RSS compliance) from the file created/moved by the social plugin into the mkdocs site dir. But, since the image is often created after the RSS plugin run, there is a race condition. In that case, the RSS plugin tries to fetch the content-length from the online image .
In the meantime, downgrading to 1.6.0 solved the issue for me. I'm not sure in which version this issue was introduced π
Downgrading to 1.9.* should be enough, before the Social Cards integration in 1.10 (https://guts.github.io/mkdocs-rss-plugin/changelog/#1100---2023-12-17 ) or even 1.10 should work before the HTTP mechanism.
Well, this not the more reliable and robust code I wrote in my life but I felt lazy back in December π . I'm going to improve it in some ways:
- using requests instead of standard lib to get the an upper-level and out-of-the-box special cases handling like SSL verification etc.
- trying to retrieve image from the local .cache folder of social plugin
- extending the social plugin manifest (in a separate file) to store image length, relying on the same cache key.
The big problem with social cards is that the link referring to the og:image
must be absolute per spec. Now, if the authors adds a new page and builds it, the URL referenced in og:image
will definitely point to a non-existing image, because the page has not been deployed to the site_url
yet. Race conditions might be a problem, but an even bigger problem is the aforementioned catch-22.
- Without the new page being deployed, no social card image
- Without the social card image, no successful build without warnings
I'm not sure what the best way forward could be.
Interesting.
extending the social plugin manifest (in a separate file) to store image length, relying on the same cache key.
Hmm it seems that the manifest.json is not systematically generated by the social plugin?
The social plugin differs between the community and Insiders edition, and only Insiders has a manifest to properly implementing caching. It will be merged once the attached funding goals are hit
Yes, I was coming to the same conclusion. I hope the sponsors are going in the right direction, it can't be easy maintaining 2 substantially different code bases!
Does the theme or theme plugins expose a variable to indicate whether it's the community or insiders version?
Something easily checkable like config.plugins.social.edition == "community"
for 3rd party plugins?
You can check the version of Material for MkDocs.
# Community
material.__version__ = "9.5.26"
# Insiders
material.__version__ = "9.5.26+insiders-4.53.11"
Thanks for the tip!
Hi @squidfunk,
Any hint on how to determine the matching hash between page filename and generated image filename in community edition I mean?
Ok, I've found the related piece of code:
hash = md5("".join([
site_name,
str(title),
description
]).encode("utf-8"))
It's much more predictable in Insiders π
Sure! But I'll try to do my best to have a similar experience in both editions.
Released as part of 1.13.1. Please test the shipped improvements and give feedback here π. Ping @alexvoss @holgerflick @domenkozar .