﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33580	Initialization of Django fails when emulated in Wine	Jochem Franken	Jochem Franken	"From version 3.2 and onwards, when running management commands, the registry is searched for the key 'Console'. In emulated environments (via Wine) this fails as the key is nonexistent.


{{{
Traceback (most recent call last):
  File ""C:\python38\lib\site-packages\django\core\management\__init__.py"", line 375, in execute
    autoreload.check_errors(django.setup)()
  File ""C:\python38\lib\site-packages\django\utils\autoreload.py"", line 64, in wrapper
    fn(*args, **kwargs)
  File ""C:\python38\lib\site-packages\django\__init__.py"", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File ""C:\python38\lib\site-packages\django\utils\log.py"", line 71, in configure_logging
    logging.config.dictConfig(DEFAULT_LOGGING)
  File ""C:\python38\lib\logging\config.py"", line 808, in dictConfig
    dictConfigClass(config).configure()
  File ""C:\python38\lib\logging\config.py"", line 545, in configure
    raise ValueError('Unable to configure '
ValueError: Unable to configure formatter 'django.server'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ""manage.py"", line 22, in <module>
    main()
  File ""manage.py"", line 18, in main
    execute_from_command_line(sys.argv)
  File ""C:\python38\lib\site-packages\django\core\management\__init__.py"", line 419, in execute_from_command_line
    utility.execute()
  File ""C:\python38\lib\site-packages\django\core\management\__init__.py"", line 388, in execute
    _parser = self.fetch_command('runserver').create_parser('django', 'runserver')
  File ""C:\python38\lib\site-packages\django\core\management\__init__.py"", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File ""C:\python38\lib\site-packages\django\core\management\__init__.py"", line 40, in load_command_class
    return module.Command()
  File ""C:\python38\lib\site-packages\django\core\management\base.py"", line 251, in __init__
    self.style = color_style(force_color)
  File ""C:\python38\lib\site-packages\django\core\management\color.py"", line 105, in color_style
    if not force_color and not supports_color():
  File ""C:\python38\lib\site-packages\django\core\management\color.py"", line 55, in supports_color
    vt_codes_enabled_in_windows_registry()
  File ""C:\python38\lib\site-packages\django\core\management\color.py"", line 36, in vt_codes_enabled_in_windows_registry
    reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Console')
FileNotFoundError: [WinError 2] File not found
}}}

The code block where the error happens is:

{{{
def vt_codes_enabled_in_windows_registry():
        """"""
        Check the Windows Registry to see if VT code handling has been enabled
        by default, see https://superuser.com/a/1300251/447564.
        """"""
        try:
            # winreg is only available on Windows.
            import winreg
        except ImportError:
            return False
        else:
            reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, ""Console"") # ERROR
            try:
                reg_key_value, _ = winreg.QueryValueEx(reg_key, ""VirtualTerminalLevel"")
            except FileNotFoundError:
                return False
            else:
                return reg_key_value == 1
}}}

Moving the indicated line into the try/except block fixes the error. "	Bug	closed	Core (Management commands)	3.2	Normal	fixed	wine, color		Ready for checkin	1	0	0	0	0	0
