I used Environment.compile_templates on windows compile templates and managed to get UnicodeDecodeError on Python 3. Issue is that when writing templates:
|
f = open(os.path.join(target, filename), mode) |
no explicit encoding is specified for
open. In my case it meant, that my utf8 encoded templates got compiled correctly, but then written as
cp1252 and failed to load, when executing.
- When explicitly specifying encoding to 'utf8' in referenced
open call compiled templates were functional.
- Enabling Python 3.7 UTF-8 mode using
PYTHONUTF8 also got rid of the issue (which forces utf8 encoding for open calls).
When I tried to provide minimal example, issue didn't trigger (files got written as 'utf8'). Copying all templates from flask project didn't also trigger issue. Then within my flask project issue is triggered, but I didn't notice any changes to encoding there.
In any case used encoding doesn't seem to be deterministic.
Perhaps somebody will experience same issue and will be able to provide minimal example.
Expected Behavior
Compiled templates are written to disk using correct encoding (utf8 in my case).
Actual Behavior
Encoding of compiled templates depends on what open call selects by default.
Your Environment
- Python version: 3.6.6 / 3.7.0
- Jinja version: 2.10
I used
Environment.compile_templateson windows compile templates and managed to get UnicodeDecodeError on Python 3. Issue is that when writing templates:jinja/jinja2/environment.py
Line 691 in f2e9280
open. In my case it meant, that my utf8 encoded templates got compiled correctly, but then written ascp1252and failed to load, when executing.opencall compiled templates were functional.PYTHONUTF8also got rid of the issue (which forces utf8 encoding for open calls).When I tried to provide minimal example, issue didn't trigger (files got written as 'utf8'). Copying all templates from flask project didn't also trigger issue. Then within my flask project issue is triggered, but I didn't notice any changes to encoding there.
In any case used encoding doesn't seem to be deterministic.
Perhaps somebody will experience same issue and will be able to provide minimal example.
Expected Behavior
Compiled templates are written to disk using correct encoding (utf8 in my case).
Actual Behavior
Encoding of compiled templates depends on what
opencall selects by default.Your Environment