Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 731faec

Browse files
committed
Read jinja template with UTF-8 encoding set explicitly
Today we started seeing an UnicodeDecodeError error, coming from the changed line: 'ascii' codec can't decode byte 0xc3 in position 2980: ordinal not in range(128). This appeared after submitting the form. The Path.read_text() function uses the locale's encoding by default. AFAIK there have been some server configuration changes recently. To my surprise, after ssh'ing into the server, I discovered that the encoding returned by locale.getencoding() was ANSI_X3.4-1968. We then changed the encoding to UTF-8 and bounced the server. When run by a user (me), the locale.getencoding() now returns UTF-8. Yet, when executed inside store_data.py, it still returns ANSI_X3.4-1968. See commit f3c82f4. This commit changes the from_string() call to explicitly use UTF-8. It should prevent locale settings from interfering with loading the template (which contains some umlauts).
1 parent f3c82f4 commit 731faec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

server/store_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ def create_result_page(commit_hash: str,
372372
templates_directory: Path):
373373

374374
jinja_template_path = templates_directory / "success.html.jinja2"
375-
jinja_template = Environment(autoescape=select_autoescape()).from_string(jinja_template_path.read_text())
375+
jinja_template = Environment(autoescape=select_autoescape()).from_string(
376+
jinja_template_path.read_text(encoding="utf-8")
377+
)
376378
return jinja_template.render(
377379
sub_project="Z03",
378380
reference=f"{time_stamp}-{commit_hash}",

0 commit comments

Comments
 (0)