[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)
This commit is contained in:
Syres916
2023-09-04 18:15:20 +01:00
committed by GitHub
parent 6da62b83fa
commit 6f57f36620

View File

@@ -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():
"<!--QSS-->", '<style type="text/css">' + ALTCSS + "</style>"
)
else:
with open(path, "r") as f:
with codecs.open(path, encoding='utf-8') as f:
ALTCSS = f.read()
HTML = HTML.replace(
"<!--QSS-->", '<style type="text/css">' + ALTCSS + "</style>"
@@ -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):