Encoding problem with configs
Posted: Wed Sep 12, 2018 5:27 pm
Hey guys,
for WCS I use this code for my core config file:
Now this works fine if SourcePython is set to english language, but as soon as you set it to russian the cyrilic alphabet seems to mess with the encoding (sorry, I'm a total noob when it comes to encodings).
This is what a user reported when changing to russian:
This is what I get when I try the same:
My exception is taken from the server console hence the messed up signs.
Could you tell me what I did wrong? Thanks :)
for WCS I use this code for my core config file:
Syntax: Select all
from config.manager import ConfigManager
from core import SOURCE_ENGINE_BRANCH
from paths import PLUGIN_DATA_PATH, GAME_PATH
import os
WCS_DATA_PATH = PLUGIN_DATA_PATH / 'wcs'
if not WCS_DATA_PATH.exists():
WCS_DATA_PATH.makedirs()
LEVELBANK_DB_PATH = WCS_DATA_PATH / 'levelbank.db'
CORE_DB_PATH = WCS_DATA_PATH / 'players.db'
CORE_DB_REL_PATH = CORE_DB_PATH.relpath(GAME_PATH.parent)
LEVELBANK_DB_REL_PATH = LEVELBANK_DB_PATH.relpath(GAME_PATH.parent)
core_config = ConfigManager('wcs/wcs_core')
saving = core_config.cvar('wcs_save_mode', 0)
save_time = core_config.cvar('wcs_save_delay', 5)
xpsaver = core_config.cvar('wcs_cfg_savexponround', 5)
db_string = core_config.cvar('wcs_database_connectstring',f'sqlite:///{CORE_DB_REL_PATH}')
lvl_string = core_config.cvar('wcs_levelbank_connectstring',f'sqlite:///{LEVELBANK_DB_REL_PATH}')
racecategories = core_config.cvar('wcs_racecats', 0)
defaultcategory = core_config.cvar('wcs_racecats_defaultcategory', 'Default category')
showracelevel = core_config.cvar('wcs_cfg_showracelevel', 1)
keyinfo = core_config.cvar('wcs_activate_keymenu', 0)
categories = core_config.cvar('wcs_activate_categories', 0)
unassigned_cat = core_config.cvar('wcs_unassigned_category', 1)
changerace_racename = core_config.cvar('wcs_changerace_racename',1)
race_in_tag = core_config.cvar('wcs_activate_clantag_races', 1)
logging = core_config.cvar('wcs_logging',1)
default_races = core_config.cvar('wcs_use_default_race_file',1)
core_config.write()
core_config.execute()
Now this works fine if SourcePython is set to english language, but as soon as you set it to russian the cyrilic alphabet seems to mess with the encoding (sorry, I'm a total noob when it comes to encodings).
This is what a user reported when changing to russian:
Code: Select all
Sep 11 19:26:26: [SP] Загрузка плагина 'wcs'...
Sep 11 19:26:26:
Sep 11 19:26:26: [SP] Перехвачено исключение:
Sep 11 19:26:26: Traceback (most recent call last):
Sep 11 19:26:26: File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
Sep 11 19:26:26: plugin = self.manager.load(plugin_name)
Sep 11 19:26:26: File "../addons/source-python/packages/source-python/plugins/manager.py", line 194, in load
Sep 11 19:26:26: plugin._load()
Sep 11 19:26:26: File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
Sep 11 19:26:26: self.module = import_module(self.import_name)
Sep 11 19:26:26: File "../addons/source-python/plugins/wcs/wcs.py", line 61, in <module>
Sep 11 19:26:26: from wcs import admin
Sep 11 19:26:26: File "../addons/source-python/plugins/wcs/admin.py", line 19, in <module>
Sep 11 19:26:26: from wcs import changerace_admin
Sep 11 19:26:26: File "../addons/source-python/plugins/wcs/changerace_admin.py", line 22, in <module>
Sep 11 19:26:26: from wcs import changerace
Sep 11 19:26:26: File "../addons/source-python/plugins/wcs/changerace.py", line 8, in <module>
Sep 11 19:26:26: from wcs import config
Sep 11 19:26:26: File "../addons/source-python/plugins/wcs/config.py", line 46, in <module>
Sep 11 19:26:26: core_config.write()
Sep 11 19:26:26: File "../addons/source-python/packages/source-python/config/manager.py", line 281, in write
Sep 11 19:26:26: open_file, section, _old_config, spaces)
Sep 11 19:26:26: File "../addons/source-python/packages/source-python/config/manager.py", line 487, in _write_cvar_section
Sep 11 19:26:26: default.format(section.default))
Sep 11 19:26:26:
Sep 11 19:26:26: UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-13: ordinal not in range(128)
Sep 11 19:26:26:
Sep 11 19:26:26:
Sep 11 19:26:26: [SP] Плагин 'wcs' не может быть загружен.
This is what I get when I try the same:
Code: Select all
sp plugin load wcs
[SP] ðùð░ð│ÐÇÐâðÀð║ð░ ð┐ð╗ð░ð│ð©ð¢ð░ 'wcs'...
[SP] ðƒðÁÐÇðÁÐàð▓ð░ÐçðÁð¢ð¥ ð©Ðüð║ð╗ÐÄÐçðÁð¢ð©ðÁ:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 193, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "..\addons\source-python\plugins\wcs\wcs.py", line 61, in <module>
from wcs import admin
File "..\addons\source-python\plugins\wcs\admin.py", line 19, in <module>
from wcs import changerace_admin
File "..\addons\source-python\plugins\wcs\changerace_admin.py", line 22, in <module>
from wcs import changerace
File "..\addons\source-python\plugins\wcs\changerace.py", line 8, in <module>
from wcs import config
File "..\addons\source-python\plugins\wcs\config.py", line 46, in <module>
core_config.write()
File "..\addons\source-python\packages\source-python\config\manager.py", line 281, in write
open_file, section, _old_config, spaces)
File "..\addons\source-python\packages\source-python\config\manager.py", line 487, in _write_cvar_section
default.format(section.default))
File "..\addons\source-python\Python3\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 3-13: character maps to <undefined>
[SP] ðƒð╗ð░ð│ð©ð¢ 'wcs' ð¢ðÁ ð╝ð¥ðÂðÁÐé ð▒ÐïÐéÐî ðÀð░ð│ÐÇÐâðÂðÁð¢.
My exception is taken from the server console hence the messed up signs.
Could you tell me what I did wrong? Thanks :)