Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#28487 closed Bug (fixed)

runserver crashes with UncodeDecodeError as of Django 1.11.4

Reported by: newerBkl Owned by: Mark Rogaski
Component: Core (Management commands) Version: 1.11
Severity: Normal Keywords:
Cc: Mark Rogaski Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My env is windows 7 x64 Python 2.7, after upgrade to 1.11.4 , i can't run manager.py runserver
In 1.11.3 is ok,anything with "Fixed crash in runserver’s autoreload with Python 2 on Windows with non-str environment variables (#28174)."
============================================================

(users) D:\django_test\dddd>pip install --upgrade django
Collecting django
  Using cached Django-1.11.4-py2.py3-none-any.whl
Requirement already up-to-date: pytz in d:\env_python\users\lib\site-packages (from django)
Installing collected packages: django
  Found existing installation: Django 1.11.3
    Uninstalling Django-1.11.3:
      Successfully uninstalled Django-1.11.3
Successfully installed django-1.11.4

(users) D:\django_test\dddd>python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "D:\env_python\users\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "D:\env_python\users\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\env_python\users\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\env_python\users\lib\site-packages\django\core\management\commands\runserver.py", line 62, in execute
    super(Command, self).execute(*args, **options)
  File "D:\env_python\users\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "D:\env_python\users\lib\site-packages\django\core\management\commands\runserver.py", line 101, in handle
    self.run(**options)
  File "D:\env_python\users\lib\site-packages\django\core\management\commands\runserver.py", line 110, in run
    autoreload.main(self.inner_run, None, options)
  File "D:\env_python\users\lib\site-packages\django\utils\autoreload.py", line 341, in main
    reloader(wrapped_main_func, args, kwargs)
  File "D:\env_python\users\lib\site-packages\django\utils\autoreload.py", line 312, in python_reloader
    exit_code = restart_with_reloader()
  File "D:\env_python\users\lib\site-packages\django\utils\autoreload.py", line 294, in restart_with_reloader
    str_value = force_bytes(new_environ[key], encoding=encoding)
  File "D:\env_python\users\lib\site-packages\django\utils\encoding.py", line 124, in force_bytes
    return s.decode('utf-8', errors).encode(encoding, errors)
  File "D:\env_python\users\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 202: invalid start byte

Attachments (1)

encoding.diff (435 bytes) - added by Jacek Kałucki 3 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 3 years ago by Tim Graham

Cc: Mark Rogaski added
Summary: Django1.11.4 Cannot run `manage.py runserver` on Windows (UnicodeDecodeError:)runserver crashes with UncodeDecodeError as of Django 1.11.4

What's the key/value of the environment variable that's causing the crash?

comment:2 in reply to:  1 Changed 3 years ago by newerBkl

Replying to Tim Graham:

What's the key/value of the environment variable that's causing the crash?

I have no idea, it's just a new project without my own code and the traceback doesn't give me any ideas about the cause.

comment:3 Changed 3 years ago by Tim Graham

You can add print(key, new_environ[key]) before the line with force_bytes(new_environ[key], encoding=encoding) to see the problematic value.

comment:4 in reply to:  3 Changed 3 years ago by newerBkl

Replying to Tim Graham:

You can add print(key, new_environ[key]) before the line with force_bytes(new_environ[key], encoding=encoding) to see the problematic value.

Thanks , here is the output

('TMP', 'C:\\Users\\100000\\AppData\\Local\\Temp')
('PSMODULEPATH', 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\')
('PROCESSOR_LEVEL', '6')
('_OLD_VIRTUAL_PATH', 'C:\\Program Files (x86)\\Common Files\\NetSarang;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Windows\\system32;C:\\Windows
;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\\xb8\xbb\xbb\xf9\xd0\xfd\xb7\xe7\xbf\xc
6\xbc\xbc\\appSys01;C:\\Program Files (x86)\\\xb8\xbb\xbb\xf9\xd0\xfd\xb7\xe7\xbf\xc6\xbc\xbc\\appSys02;C:\\Program Files (x86)\\\xb8\xbb\xbb\
xf9\xd0\xfd\xb7\xe7\xbf\xc6\xbc\xbc\\appSys01;C:\\Program Files (x86)\\\xb8\xbb\xbb\xf9\xd0\xfd\xb7\xe7\xbf\xc6\xbc\xbc\\appSys02;C:\\Program
Files (x86)\\\xb8\xbb\xbb\xf9\xd0\xfd\xb7\xe7\xbf\xc6\xbc\xbc\\appSys03;C:\\Program Files\\TortoiseSVN\\bin;;C:\\Program Files\\Microsoft VS C
ode\\bin')
Traceback (most recent call last):
....
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 202: invalid start byte

there was a path with Chinese in my system_path. the Chinese is

C:\Program Files (x86)\富基旋风科技\appSys01


After removing ,it works well.By the way ,my system_encoding is cp936

Last edited 3 years ago by newerBkl (previous) (diff)

Changed 3 years ago by Jacek Kałucki

Attachment: encoding.diff added

comment:5 Changed 3 years ago by Mark Rogaski

Owner: changed from nobody to Mark Rogaski
Status: newassigned

comment:6 Changed 3 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:7 Changed 2 years ago by Tim Graham

Has patch: set

PR with the patch from Jacek Kałucki to alter force_bytes().

Last edited 2 years ago by Tim Graham (previous) (diff)

comment:8 Changed 2 years ago by Tim Graham

New PR that only touches the autoreloader instead of changing force_bytes().

comment:9 Changed 2 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

comment:10 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 80a0016:

[1.11.x] Fixed #28487 -- Fixed runserver crash with non-Unicode system encodings on Python 2 + Windows.

comment:11 Changed 2 years ago by Tim Graham <timograham@…>

In 11cd4693:

Refs #28487 -- Forwardported 1.11.5 release note.

Note: See TracTickets for help on using tickets.
Back to Top