From 190c63c594c32e21566adaebf59f26d2f6b66274 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 26 Jul 2018 18:19:52 -0500 Subject: [PATCH] site: Specify UTF-8 encoding for songquotes In some cases, the default codec used by PyYAML is not UTF-8, so loading the song quotes database fails. Using the `codecs.open` helper function ensures that the contents of the file are always read with the correct character set. --- site.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site.py b/site.py index aac5d0c..d012da9 100644 --- a/site.py +++ b/site.py @@ -1,5 +1,6 @@ from milla.dispatch import routing from webob import acceptparse +import codecs import jinja2 import milla import os @@ -24,7 +25,8 @@ env = jinja2.Environment( ) -with open(os.path.join(os.path.dirname(__file__), 'songquotes.yml')) as f: +songquotes = os.path.join(os.path.dirname(__file__), 'songquotes.yml') +with codecs.open(songquotes, 'r', encoding='utf-8') as f: songquotes = yaml.load(f, Loader=YamlLoader)