From 6f57f36620354011c708edc00a7cc220ef97b1dc Mon Sep 17 00:00:00 2001
From: Syres916 <46537884+Syres916@users.noreply.github.com>
Date: Mon, 4 Sep 2023 18:15:20 +0100
Subject: [PATCH] [Start] Fix Python 3.11 Unicode Errors
Example Error :
File "/home/john/freecad-daily-build/Mod/Start/StartPage/StartPage.py", line 422, in handle
ALTCSS = f.read()
^^^^^^^^
File "/usr/lib/python3.11/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 421: ordinal not in range(128)
---
src/Mod/Start/StartPage/StartPage.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py
index 4951d960bf..a48ea7354e 100644
--- a/src/Mod/Start/StartPage/StartPage.py
+++ b/src/Mod/Start/StartPage/StartPage.py
@@ -32,6 +32,7 @@ import zipfile
import re
import FreeCAD
import FreeCADGui
+import codecs
import urllib.parse
from . import TranslationTexts
from PySide import QtCore, QtGui
@@ -424,7 +425,7 @@ def handle():
"", '"
)
else:
- with open(path, "r") as f:
+ with codecs.open(path, encoding='utf-8') as f:
ALTCSS = f.read()
HTML = HTML.replace(
"", '"
@@ -789,9 +790,13 @@ def exportTestFile():
"Allow to check if everything is Ok"
- f = open(os.path.expanduser("~") + os.sep + "freecad-startpage.html", "w")
- f.write(handle())
- f.close()
+ with codecs.open(
+ os.path.expanduser("~") + os.sep + "freecad-startpage.html",
+ encoding="utf-8",
+ mode="w",
+ ) as f:
+ f.write(handle())
+ f.close()
def postStart(switch_wb=True):