Skip to content

Commit a92eb00

Browse files
Merge pull request #46 from OpenAstroTech/bugfix/js/45-unicode-decode-error
Fix text byte decoding to not use strict error handling
2 parents 409c688 + 729ca48 commit a92eb00

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

OATFWGUI/anon_usage_data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from platform_check import get_platform, PlatformEnum
1717
from gui_state import LogicState
18+
from misc_utils import decode_bytes
1819

1920
log = logging.getLogger('')
2021

@@ -163,7 +164,7 @@ def get_uuid_windows() -> str:
163164
capture_output=True)
164165
if sub_proc.returncode != 0:
165166
return 'unknown-windows'
166-
windows_uuid = sub_proc.stdout.decode('UTF-8')
167+
windows_uuid = decode_bytes(sub_proc.stdout)
167168
return windows_uuid
168169

169170

@@ -185,7 +186,7 @@ def to_nearest_half(num: float) -> float:
185186
def get_approx_location() -> Tuple[float, float]:
186187
geo_ip_url = 'https://ipinfo.io/loc'
187188
response = requests.get(geo_ip_url, timeout=2.0)
188-
resp_str = response.content.decode().strip()
189+
resp_str = decode_bytes(response.content).strip()
189190
lat_str, lon_str = resp_str.split(',')
190191
lat_approx = to_nearest_half(float(lat_str))
191192
lon_approx = to_nearest_half(float(lon_str))

OATFWGUI/external_processes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from PySide6.QtCore import Slot, QProcess, QStandardPaths, QProcessEnvironment
77

8+
from misc_utils import decode_bytes
9+
810
log = logging.getLogger('')
911

1012

@@ -62,14 +64,14 @@ def cleanup(self):
6264
@Slot()
6365
def handle_stderr(self):
6466
data = self.qproc.readAllStandardError()
65-
stderr = bytes(data).decode("utf8")
67+
stderr = decode_bytes(bytes(data))
6668
self.stderr_text += stderr
6769
log.error(stderr)
6870

6971
@Slot()
7072
def handle_stdout(self):
7173
data = self.qproc.readAllStandardOutput()
72-
stdout = bytes(data).decode("utf8")
74+
stdout = decode_bytes(bytes(data))
7375
self.stdout_text += stdout
7476
log.info(stdout)
7577

OATFWGUI/misc_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ def remove_readonly(func: Callable, path, excinfo):
1616
func(path)
1717

1818
shutil.rmtree(dir_to_delete, onerror=remove_readonly)
19+
20+
21+
def decode_bytes(byte_string: bytes) -> str:
22+
# Just to consolidate all text decoding and make sure they're all the same
23+
return byte_string.decode('utf-8', errors='backslashreplace')

0 commit comments

Comments
 (0)