Setting the post date to a value in March crashes Blogofile
christianspecht opened this issue · 3 comments
TL;DR:
Blogofile crashes when I set the post date to a date where the month name in my machine's default language contains an umlaut (in my case, the language is German and the umlaut is in "März", which is the German word for the month March).
I avoided the problem by setting the locale to English before the build. This works for me because I want to blog in English anyway, but it won't work for people who want to blog in a language with umlauts.
Long version:
I just discovered Blogofile a few hours ago, and I'm just trying to create my first site.
I ran into this issue first when I created a new site, and tried to add a new post (with a date in March 2012) to it.
Then I discovered that I get the same error when I change the post date in one of the default example posts.
After playing around with some test values, I found out that this error occurs whenever I set the post date to a value between March 1st and March 31st, no matter which year (I tested 2009 to 2012).
Here are the steps to reproduce the problem:
I'm using:
- Blogofile 0.8b1
- Python 2.7.1
- Windows 7 Home Premium SP 1 (in German, if that matters)
I create a new site according to the quick tutorial:
blogofile init mysite blog
blogofile build -s mysite
blogofile serve -s mysite
Blogofile compiles and I can view the site via http://localhost:8080.
Then I change the YAML header of this file:
\mysite\_posts\000 - filler1.markdown
By default, the header says this:
date: 2010/06/29 15:25:00
I change the month to March:
date: 2010/03/29 15:25:00
Then I try to build the site again:
blogofile build -s mysite
Blogofile crashes and outputs this:
ERROR:blogofile.template:Error rendering template: permapage.mako
Traceback (most recent call last):
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\template.py", line 157, in render
rendered = self.mako_template.render(**self)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "_templates/base.mako", line 2, in render_body
${next.body()}
File "_templates/site.mako", line 20, in render_body
${next.body()}
File "_templates/blog/permapage.mako", line 2, in render_body
<%include file="post.mako" args="post=post" />
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 693, in _include_file
callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
File "_templates/blog/post.mako", line 18, in render_body
<p><small><span class="blog_post_date">${post.date.strftime("%B %d, %Y at %I
:%M %p")}</span> | categories:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal
not in range(128)
ERROR:blogofile:Fatal build error occured, calling bf.config.build_exception()
Traceback (most recent call last):
File "C:\Program Files (x86)\Python27\Scripts\blogofile-script.py", line 8, in
<module>
load_entry_point('blogofile==0.8b1', 'console_scripts', 'blogofile')()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\main.py", line 58, in main
args.func(args)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\main.py", line 388, in do_build
writer.write_site()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\writer.py", line 49, in write_site
self.__run_controllers()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\writer.py", line 162, in __run_controllers
controller.run_all(namespaces)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\controller.py", line 229, in run_all
c.mod.run()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile_blog-0.8b1-p
y2.7.egg\blogofile_blog\site_src\_controllers\blog\__init__.py", line 80, in run
permapage.run()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile_blog-0.8b1-p
y2.7.egg\blogofile_blog\site_src\_controllers\blog\permapage.py", line 12, in ru
n
write_permapages()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile_blog-0.8b1-p
y2.7.egg\blogofile_blog\site_src\_controllers\blog\permapage.py", line 38, in wr
ite_permapages
"permapage.mako", bf.util.path_join(path, "index.html"), env)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\plugin.py", line 160, in materialize_template
lookup=self.template_lookup, caller=self.module)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\template.py", line 388, in materialize_template
template.render(location)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\template.py", line 157, in render
rendered = self.mako_template.render(**self)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "base_mako", line 23, in render_body
File "site_mako", line 41, in render_body
File "permapage_mako", line 35, in render_body
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\runtime.py", line 693, in _include_file
callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
File "post_mako", line 49, in render_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal
not in range(128)
I suppose that I know now why this happens:
March means März in German (notice the ä) and it's the only German month that has an umlaut in its name.
It's pretty clear if you read the error message (it says that a UnicodeDecodeError
happened), but I didn't see the connection at the time.
I found out about this because I'm trying to translate the output of bf.config.blog.archive_links
right now.
I wasn't able to come up with a better solution, so I just replace the German month names with the English ones:
% for link, name, num_posts in bf.config.blog.archive_links:
<%
if name.startswith('Januar'):
month=name.replace('Januar','January')
elif name.startswith('Februar'):
month=name.replace('Februar','February')
[...]
else:
month=name
%>
<li><a href="${bf.util.site_path_helper(bf.config.blog.path,link)}/1">${month} (${num_posts})</a></li>
% endfor
Basically, this works, but as soon as I insert the lines for März (March), Blogofile crashes with the error below.
The last line says mako.exceptions.CompileException: Unicode decode operation of encoding 'utf-8' failed in file '_templates/site.mako' at line: 0 char: 0
, so I guess it's actually a bug in Mako, not in Blogofile?
ERROR:blogofile:Fatal build error occured, calling bf.config.build_exception()
Traceback (most recent call last):
File "C:\Program Files (x86)\Python27\Scripts\blogofile-script.py", line 8, in
<module>
load_entry_point('blogofile==0.8b1', 'console_scripts', 'blogofile')()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\main.py", line 58, in main
args.func(args)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\main.py", line 388, in do_build
writer.write_site()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\writer.py", line 49, in write_site
self.__run_controllers()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\writer.py", line 162, in __run_controllers
controller.run_all(namespaces)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\controller.py", line 229, in run_all
c.mod.run()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile_blog-0.8b1-p
y2.7.egg\blogofile_blog\site_src\_controllers\blog\__init__.py", line 80, in run
permapage.run()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile_blog-0.8b1-p
y2.7.egg\blogofile_blog\site_src\_controllers\blog\permapage.py", line 12, in ru
n
write_permapages()
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile_blog-0.8b1-p
y2.7.egg\blogofile_blog\site_src\_controllers\blog\permapage.py", line 38, in wr
ite_permapages
"permapage.mako", bf.util.path_join(path, "index.html"), env)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\plugin.py", line 160, in materialize_template
lookup=self.template_lookup, caller=self.module)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\template.py", line 388, in materialize_template
template.render(location)
File "C:\Program Files (x86)\Python27\lib\site-packages\blogofile-0.8b1-py2.7.
egg\blogofile\template.py", line 155, in render
bf.config.site.base_template))
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\lookup.py", line 240, in get_template
return self._load(srcfile, uri)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\lookup.py", line 306, in _load
**self.template_args)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\template.py", line 291, in __init__
module = self._compile_from_file(path, filename)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\template.py", line 368, in _compile_from_file
filename)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\template.py", line 615, in _compile_text
generate_magic_comment=template.disable_unicode)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\template.py", line 597, in _compile
node = lexer.parse()
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\lexer.py", line 214, in parse
self.filename,)
File "C:\Program Files (x86)\Python27\lib\site-packages\mako-0.7.2-py2.7.egg\m
ako\lexer.py", line 206, in decode_raw_stream
0, 0, filename)
mako.exceptions.CompileException: Unicode decode operation of encoding 'utf-8' f
ailed in file '_templates/site.mako' at line: 0 char: 0
Okay, I just found out that everything works for me when I set the locale completely to English by putting this into config.py:
def pre_build():
import locale
locale.setlocale(locale.LC_ALL, 'english')
(thanks to Peter Zsoldos for pointing me to this)
So the problem has disappeared for me, but everyone who tries to use Blogofile to blog in German (or, probably, any language containing umlauts) will still have the same problem.