1 | | Replying to [ticket:23265 SpaceFox]: |
2 | | > On Windows / Python 2.7, if Django is set to use the French locale ("fra"), an UTF8 encoding error prevents it to start with this stack trace: |
3 | | > |
4 | | > |
5 | | > {{{ |
6 | | > Validating models... |
7 | | > |
8 | | > 0 errors found |
9 | | > Unhandled exception in thread started by <function wrapper at 0x0000000003F33B38> |
10 | | > Traceback (most recent call last): |
11 | | > File "C:\Users\SpaceFox\.virtualenvs\zdsenv\lib\site-packages\django\utils\autoreload.py", line 93, in wrapper |
12 | | > fn(*args, **kwargs) |
13 | | > File "C:\Users\SpaceFox\.virtualenvs\zdsenv\lib\site-packages\django\core\management\commands\runserver.py", line 104, |
14 | | > in inner_run |
15 | | > now = now.decode('utf-8') |
16 | | > File "C:\Users\SpaceFox\.virtualenvs\zdsenv\lib\encodings\utf_8.py", line 16, in decode |
17 | | > return codecs.utf_8_decode(input, errors, True) |
18 | | > UnicodeDecodeError: 'utf8' codec can't decode byte 0xfb in position 2: invalid start byte |
19 | | > }}} |
20 | | > |
21 | | > How to reproduce this: |
22 | | > |
23 | | > - Windows (tested on Windows 8.1 x64), all updates OK |
24 | | > - Python 2.7 (Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32) |
25 | | > - Django 1.6.5 |
26 | | > - In settings.py, set locale to "fra": {{{locale.setlocale(locale.LC_TIME, 'fra')}}} |
27 | | > - Try to launch Django with {{{python manage.py runserver}}}. Kabooom! |
28 | | > |
29 | | > The problem comes for the django/core/management/commands/runserver.py line 102 to 104 : |
30 | | > |
31 | | > {{{ |
32 | | > now = datetime.now().strftime('%B %d, %Y - %X') |
33 | | > if six.PY2: |
34 | | > now = now.decode('utf-8') |
35 | | > }}} |
36 | | > |
37 | | > These 3 lines suppose the strftime method returns an UTF-8 string... this is false when Django runs on Windows with Python 2.7. |
38 | | > |
39 | | > In French language, 3 month names have non-ASCII characters: "février", "août" and "décembre" (February, August and December). |
40 | | > |
41 | | > With described parameters, {{{now}}} is set as "ao¹t 09, 2014 - 00:56:41". The crap that replaces the "û" character in "août" contains the 0xfb character, which is illegal in UTF-8. This create the crash. |
42 | | > |
43 | | > The problem is the same in February and December due to the 0xe9 byte in {{{now}}}, caused by the "é" character. |
44 | | > |
45 | | > With other non-ASCII characters, this may "work" as long as there is no illegal byte in the given string: the output of this function will be broken (not what is expected) but there will be no exception thrown. |
46 | | > |
47 | | > I don't know how to correct this, therefore I can't provide any patch. |