#1938·skills

docx skill: validate.py crashes/fails on Windows due to cp1252 encoding (fontTable.xml decode + console print)

Author: sergiodanielaleCreated Sep 29, 2026Updated Sep 29, 2026

Summary

scripts/office/validate.py in the docx skill fails on Windows with a UnicodeDecodeError while reading word/fontTable.xml, and separately crashes with an unhandled UnicodeEncodeError in its own status output. Both are encoding bugs in the validator itself, reproducible on a completely empty python-docx document — not related to any specific document content.

Repro

python
from docx import Document
Document().save("empty-test.docx")
bash
python scripts/office/validate.py empty-test.docx

Observed output

FAILED - Found NEW validation errors:
  word\fontTable.xml: 1 new error(s)
    - 'charmap' codec can't decode byte 0x9d in position 1295: character maps to <undefined>
  word\settings.xml: 1 new error(s)
    - Element '{...}zoom': The attribute '{...}percent' is required but missing.
Traceback (most recent call last):
  ...
  File ".../validators/docx.py", line 249, in compare_paragraph_counts
    print(f"\nParagraphs: {original_count} → {new_count} ({diff_str})")
UnicodeEncodeError: 'charmap' codec can't encode character '→' in position 16: character maps to <undefined>

Root cause (as far as we could tell)

  1. fontTable.xml decode error — the default python-docx template embeds a font table that includes East Asian font names (e.g. "MS Mincho"). Whatever file-reading path the validator uses for fontTable.xml opens it with the platform default encoding (cp1252 on Windows) instead of explicit utf-8, so bytes outside the cp1252 codepage raise UnicodeDecodeError.
  2. Console print crash — validators/docx.py's compare_paragraph_counts prints a literal → (→) via print(), which on a Windows console with the default cp1252 code page raises UnicodeEncodeError and crashes the whole validation run with a traceback instead of a clean pass/fail result.

Workaround we're using: run with PYTHONIOENCODING=utf-8 (and PYTHONUTF8=1) set, which avoids both issues. But this isn't documented anywhere in the skill, and a first-time Windows user hits a hard crash with the default python.exe.

Suggested fix

  • Open all XML files read for validation with encoding="utf-8" explicitly (or errors="replace" as a fallback), rather than relying on the platform locale.
  • Replace the print(f"...→...") with either an ASCII-safe arrow (->) or force UTF-8 stdout (sys.stdout.reconfigure(encoding="utf-8") at the top of the script, Python 3.7+) so the validator doesn't crash on Windows consoles with a non-UTF-8 code page.

Separate, unrelated finding worth noting

The zoom element missing w:percent in settings.xml is a real (if minor) gap in python-docx's default template — not a validator bug, just flagging it here since it showed up in the same repro. We worked around it with a small post-processing step on our end.

Environment

  • Windows 11
  • Python 3.14 (also likely affects any Python on Windows with default cp1252 locale)
  • python-docx (latest via pip)
  • Skill: document-skills:docx (this repo, skills/docx)