Skip to content

Commit 0b04176

Browse files
committed
Rev4203, Change console encoding to utf8 on Windows
1 parent 166a65e commit 0b04176

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/Config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Config(object):
1313

1414
def __init__(self, argv):
1515
self.version = "0.7.0"
16-
self.rev = 4200
16+
self.rev = 4203
1717
self.argv = argv
1818
self.action = None
1919
self.pending_changes = {}

src/Crypt/CryptConnection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ def createSslRsaCert(self):
137137
cmd, shell=True, stderr=subprocess.STDOUT,
138138
stdout=subprocess.PIPE, env=self.openssl_env
139139
)
140-
back = proc.stdout.read().strip().replace(b"\r", b"")
140+
back = proc.stdout.read().strip().decode(errors="replace").replace("\r", "")
141141
proc.wait()
142142

143143
if not (os.path.isfile(self.cacert_pem) and os.path.isfile(self.cakey_pem)):
144144
self.log.error("RSA ECC SSL CAcert generation failed, CAcert or CAkey files not exist. (%s)" % back)
145145
return False
146146
else:
147-
self.log.debug("Result: %s" % back.decode())
147+
self.log.debug("Result: %s" % back)
148148

149149
# Generate certificate key and signing request
150150
cmd_params = helper.shellquote(
@@ -160,7 +160,7 @@ def createSslRsaCert(self):
160160
cmd, shell=True, stderr=subprocess.STDOUT,
161161
stdout=subprocess.PIPE, env=self.openssl_env
162162
)
163-
back = proc.stdout.read().strip().decode().replace("\r", "")
163+
back = proc.stdout.read().strip().decode(errors="replace").replace("\r", "")
164164
proc.wait()
165165
self.log.debug("Running: %s\n%s" % (cmd, back))
166166

@@ -179,7 +179,7 @@ def createSslRsaCert(self):
179179
cmd, shell=True, stderr=subprocess.STDOUT,
180180
stdout=subprocess.PIPE, env=self.openssl_env
181181
)
182-
back = proc.stdout.read().strip().decode().replace("\r", "")
182+
back = proc.stdout.read().strip().decode(errors="replace").replace("\r", "")
183183
proc.wait()
184184
self.log.debug("Running: %s\n%s" % (cmd, back))
185185

src/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@
7676
if config.msgpack_purepython:
7777
os.environ["MSGPACK_PUREPYTHON"] = "True"
7878

79+
# Fix console encoding on Windows
80+
if sys.platform.startswith("win"):
81+
import subprocess
82+
try:
83+
chcp_res = subprocess.check_output("chcp 65001", shell=True).decode(errors="ignore").strip()
84+
logging.debug("Changed console encoding to utf8: %s" % chcp_res)
85+
except Exception as err:
86+
logging.error("Error changing console encoding to utf8: %s" % err)
87+
7988
# Socket monkey patch
8089
if config.proxy:
8190
from util import SocksProxy

0 commit comments

Comments
 (0)