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

Determine where TypeError: not all arguments converted during string formatting is occuring? #2489

Closed
AWegnerGitHub opened this issue Dec 7, 2018 · 21 comments

Comments

@AWegnerGitHub
Copy link

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?

@julien-h
Copy link

julien-h commented Dec 7, 2018

This error occurs even with the builtin theme "simple". I opened an issue about this here: #2487

@bryanbrattlof
Copy link
Contributor

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.

@AWegnerGitHub
Copy link
Author

  File "/home/andy/.virtualenvs/pelican_test/bin/pelican", line 11, in <module>
    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
    <link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_ATOM|format(cat_name) }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME|striptags|e }} - {{category[0]}} Category Atom
Feed" />
  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. 

@moorepants
Copy link
Contributor

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:

https://travis-ci.org/mechmotum/mechmotum.github.io/builds/468508535?utm_source=github_status&utm_medium=notification

I cannot reproduce the error locally with the same Python and Pelican versions.

@bryanbrattlof
Copy link
Contributor

bryanbrattlof commented Dec 15, 2018

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.

@moorepants
Copy link
Contributor

Funny, I was pretty sure I disabled that theme on this commit: mechmotum/mechmotum.github.io@866dfc4 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?

@moorepants
Copy link
Contributor

My travis script also clones from https://github.com/gfidente/pelican-svbhack/ directly on each build, so it should have master.

@bryanbrattlof
Copy link
Contributor

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?

@moorepants
Copy link
Contributor

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.

@moorepants
Copy link
Contributor

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

@moorepants
Copy link
Contributor

Hmm, it is supposed to clone the PR branch maybe.

@moorepants
Copy link
Contributor

No, it is working as expected. I think the theme just needs to be updated.

@bryanbrattlof
Copy link
Contributor

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

@moorepants
Copy link
Contributor

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.

@justinmayer
Copy link
Member

justinmayer commented Dec 15, 2018 via email

@moorepants
Copy link
Contributor

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?

@joetechem
Copy link

joetechem commented Dec 28, 2018

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

mrshu added a commit to mrshu/pelican that referenced this issue Mar 1, 2019
* The `simple` template that is bundled with Pelican has been shown to
  suffer from the problem described in getpelican#2489. This has also been
  reported as a bug in the Debian Bug tracer:
  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=919636

* This commit fixes the problem by updating the `simple` template to the
  new way of interpolating variables via the Jinja2 `format` helper
  function.

Signed-off-by: mr.Shu <mr@shu.io>
@mirajpatel19
Copy link

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

Naereen added a commit to Naereen/cuisine that referenced this issue Mar 21, 2019
Naereen added a commit to Naereen/Objectif-Zero-Dechet-2018 that referenced this issue Mar 22, 2019
@monperrus
Copy link

monperrus commented Apr 27, 2019

Many themes in https://github.com/getpelican/pelican-themes/ are broken, I get this error for 3/4 themes I tried: simple, neat, medius

kiyui pushed a commit to kiyui/dont-reinvent-bicycle that referenced this issue Apr 30, 2019
kiyui added a commit to kiyui/dont-reinvent-bicycle that referenced this issue Apr 30, 2019
@alarig
Copy link

alarig commented Jan 13, 2020

I had this issue even if I don’t 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.

@philippludwig
Copy link

philippludwig commented Jun 5, 2020

So, is there any fix for this? I can’t publish anything on my blog anymore because of this issue.

Edit: Nevermind, the fix by mirajpatel19 works as described.

christianmlong added a commit to christianmlong/blue-penguin that referenced this issue Mar 30, 2024
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

No branches or pull requests

10 participants