Skip to content

Wrong encoding when runned via module #93

Closed

Description

@cvas22

Copied from python-docx-template issue 516, opened by @netaddict on 2023-11-08.


Hi,

when I start docxtpl from the command line as module and my json file contains UTF-8 encoded special characters, they seem to be wrong encoded in the resulting docx.

To reproduce it, simply add a character like "ä" in the
tests/templates/module_execute.json file and run the module_execute.py in the tests directory.


Comments from the original thread

@elapouya on 2023-11-13:

Cannot reproduce the problem by adding "ä", please provide your json file.

@netaddict on 2023-11-16:

Tested it again on MacOS, seems ok here. Another Test on Windows (x64 Python 3.10.9) failed somewhat (see files attached).

module_execute.json
module_execute.docx

@SergeyZaykov on 2023-11-20:

I see the wrong character at your DOCX file but I can't reproduce it. (Python 3.10.13, docxtpl 0.16.5)
Moreover I add to JSON chinese characters and some arabic characters. For me all characters are OK.

module_execute.json
module_execute.docx

Which version of docxtpl are you using?

@SergeyZaykov on 2023-11-20:

Well on another machine (Python 3.11.2, docxtpl 0.16.6) I can reproduce the problem.
Nor umlauts letter nor chinese characters nor arabic characters doesn't rendered correctly.

@elapouya on 2024-01-03:

Still cannot reproduce the problem : @SergeyZaykov : please provide .docx template and .json file.

@SergeyZaykov on 2024-01-09:

@elapouya
Here are the problematic template and the JSON data.:
module_execute.json
module_execute_tpl.docx
Python 3.11.2
docxtpl 0.16.6

@dmitriadov on 2025-08-27:

Same issue for me - any Unicode symbols rendered incorrectly when running via module. I think the issue is in get_json_data - it should open the json file with utf-8 encoding.

Activity

  1. added
    bug
    on Nov 9, 2026
  2. cvas22 commented on Nov 22, 2026

    @cvas22
    OwnerAuthor

    @netaddict @SergeyZaykov @dmitriadov @davidpavlovschi fixed in #173, the CLI reads JSON and writes XML as UTF-8 regardless of the system locale now, so characters like ä come through on Windows too. Thx for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions