With Pelican 4.0 there was a change made regarding position argument formatting:
Some user-submitted themes use positional argument formatting on object-related feed URLs, which will cause sites to fail to build with: "TypeError: not all arguments converted during string formatting". In that case, the theme needs to be updated.
The one that I fixed was CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml' to CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml'
My problem is that I am still encountering this TypeError and I'm not sure where. This is my verbose build output:
$ pelican content --output output --settings publishconf.py --verbose
-> Writing /home/andy/my_repos/test_pelican/output/feeds/all.atom.xml
-> Writing /home/andy/my_repos/test_pelican/output/feeds/review.atom.xml
-> Writing /home/andy/my_repos/test_pelican/output/hello-world.html
-> Writing /home/andy/my_repos/test_pelican/output/index.html
-> Writing /home/andy/my_repos/test_pelican/output/tags.html
CRITICAL: TypeError: not all arguments converted during string formatting
If I run --print-settings, the only setting with a % in it is DEFAULT_DATE_FORMAT which is unchanged from the default value of '%a %d %B %Y' set in Pelican's settings.py on line 118
How can I determine where or what is causing the TypeError?
This error occurs even with the builtin theme "simple". I opened an issue about this here: https://github.com/getpelican/pelican/issues/2487
Hi'ya @julien-h and @AWegnerGitHub
I've been messing around with this for a little bit, but I'm unsure if the error I'm getting is the same as yours. The TypeError I'm getting is related to the base.html template using the old format to generate the urls.
CATEGORY_FEED_ATOM|format(category.slug)
TAG_FEED_ATOM|format(tag.slug)
If that's the same error then we just need to use the keyword argument
CATEGORY_FEED_ATOM|format(slug=category.slug)
TAG_FEED_ATOM|format(slug=tag.slug)
If you don't mind posting what pelican in debug mode (pelican -D content) tells you, I think that might help here.
There was some work done to bring the atom/rss feed settings inline with the rest of the settings, #2437, #2383 but I'm guessing there are some bugs still.
```Traceback (most recent call last):
File "/home/andy/.virtualenvs/pelican_test/bin/pelican", line 11, in
sys.exit(main())
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/__init__.py", line 623, in main
pelican.run()
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/__init__.py", line 190, in run
p.generate_output(writer)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/generators.py", line 689, in generate_output
self.generate_pages(writer)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/generators.py", line 600, in generate_pages
self.generate_direct_templates(write)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/generators.py", line 551, in generate_direct_templates
page_name=os.path.splitext(save_as)[0], url=url)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/writers.py", line 254, in write_file
override_output)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/pelican/writers.py", line 186, in _write_file
output = template.render(localcontext)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, args, *kwargs)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/andy/my_repos/test_pelican/pelican-themes/elegant/templates/categories.html", line 1, in top-level template code
{% extends 'base.html' %}
File "/home/andy/my_repos/test_pelican/pelican-themes/elegant/templates/base.html", line 48, in top-level template code
{% block feed_links %}
File "/home/andy/my_repos/test_pelican/pelican-themes/elegant/templates/categories.html", line 29, in block "feed_links"
{% include '_includes/feeds_categories.html' %}
File "/home/andy/my_repos/test_pelican/pelican-themes/elegant/templates/_includes/feeds_categories.html", line 4, in top-level template code
File "/home/andy/.virtualenvs/pelican_test/lib/python3.6/site-packages/jinja2/filters.py", line 685, in do_format
return soft_unicode(value) % (kwargs or args)
TypeError: not all arguments converted during string formatting```
I am using the elegant theme. This helped me find the issue. Thank you for the -D pointer.
I am getting this same error on Travis where I build the website, but the -D flag doesn't seem to offer any insight, for example:
I cannot reproduce the error locally with the same Python and Pelican versions.
Hi @moorepants,
I dug through your config file (assuming this is yours) which brought me to this theme.
From the log output I'm assuming it started working on building each category page when it failed. (It was working fine with each tag page, maybe each category was next)
So I dug through the theme's repository and found this
{% if CATEGORY_FEED_ATOM %}
<link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_ATOM|format(category.slug) }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} {{ category }} Category Atom" />
{% endif %}
{% if CATEGORY_FEED_RSS %}
<link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_RSS|format(category.slug) }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} {{ category }} Category RSS" />
{% endif %}
{% endblock %}
I haven't looked much further yet but I'm guessing it's the same problem. We just need to edit the CATEGORY_FEED_ATOM and CATEGORY_FEED_RSS to the new system.
I did notice though that pelican-themes is pegged to an older version of that theme (3170593), tracking the current master seems to have the proper updates.
So this might mean pelican-themes needs an update?
Never mind, (my mind is on holiday) sorry.
Funny, I was pretty sure I disabled that theme on this commit: https://github.com/mechmotum/mechmotum.github.io/commit/866dfc4f43c328988d4e21850e805d22b7363c28 and Travis still failed.
I can submit a PR to the theme to fix this. Is there a standard setup so that the theme can work with Pelican 3 and 4? Is this a 4.0 backwards incompatibility?
My travis script also clones from https://github.com/gfidente/pelican-svbhack/ directly on each build, so it should have master.
the only thing that is making me a little confused it this line in the Travis output
git clone --depth=50 --branch=source https://github.com/mechmotum/mechmotum.github.io.git
Is Travis cloning the source branch or master when it fails?
It clones the source branch. It is supposed to. For the doctr tool to work with github pages it has to be on a branch other than master.
This is docs for doctr that shows why I'm using the source branch: https://drdoctr.github.io/recipes.html#using-doctr-with-github-io-pages
Hmm, it is supposed to clone the PR branch maybe.
No, it is working as expected. I think the theme just needs to be updated.
Haha I came here just to say that, #2437 makes it so we have to update the theme repository to the new ways for the atom/rss feeds
That's unfortunate. Would be nice if it was backwards compatible and a deprecation warning was raised instead of triggering the TypeError with no useful traceback when themes are using the old API.
A pull request to that effect would be welcome... 馃榿
Should the themes have something like:
if pelican < 4.0:
don't use slug=
else:
use slug=
Or do themes not need to work with older versions of pelican?
@moorepants @bryanbrattlof
Try editing base.html, worked for me. I guess it's just the theme (nest) is outdated for Pelican 4.0
Had to add in a slug=
nest/templates/base.html:
<link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_ATOM|format(slug=category.slug) }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Categories Atom Feed" />
{% endif %}
{% if CATEGORY_FEED_RSS and category %}
<link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_RSS|format(slug=category.slug) }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Categories RSS Feed" />
{% endif %}
{% if TAG_FEED_ATOM and tag %}
<link href="{{ FEED_DOMAIN }}/{{ TAG_FEED_ATOM|format(slug=tag.slug) }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Tags Atom Feed" />
{% endif %}
{% if TAG_FEED_RSS and tag %}
<link href="{{ FEED_DOMAIN }}/{{ TAG_FEED_RSS|format(slug=tag.slug) }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Tags RSS Feed" />
{% endif %}
<!-- /RSS Feeds -->
Along with this, had to make a few more edits (not sure if they were neccessary): adding u's to force unicode and keeping with just apostrophe enclosures instead of double quotes.
Travis still complains about the %s deprecated, but it passes the build.
Go to base.html file, which is usually in templates folder of any theme. Then find '|format(' and replace it with '.format(slug=' without quotes. That should fix the error ''TypeError: not all arguments converted during string formatting."
Many themes in https://github.com/getpelican/pelican-themes/ are broken, I get this error for 3/4 themes I tried: simple, neat, medius
I had this issue even if I don鈥檛 call CATEGORY_FEED_ATOM and CATEGORY_FEED_RSS in base.html and I already have 'feeds/{slug}.atom.xml' and 'feeds/{slug}.rss.xml' respectively. Commenting them in the config solved the issue for me.
So, is there any fix for this? I can鈥檛 publish anything on my blog anymore because of this issue.
Edit: Nevermind, the fix by mirajpatel19 works as described.
Most helpful comment
Hi'ya @julien-h and @AWegnerGitHub
I've been messing around with this for a little bit, but I'm unsure if the error I'm getting is the same as yours. The
TypeErrorI'm getting is related to thebase.htmltemplate using the old format to generate the urls.If that's the same error then we just need to use the keyword argument
If you don't mind posting what
pelicanin debug mode (pelican -D content) tells you, I think that might help here.There was some work done to bring the atom/rss feed settings inline with the rest of the settings, #2437, #2383 but I'm guessing there are some bugs still.