mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 17:57:09 +00:00
specify default encoding explicitly
This commit is contained in:
@@ -126,13 +126,16 @@ def expowebpage(request, expowebpath, path):
|
|||||||
return render(request, 'pagenotfound.html', {'path': path}, status="404")
|
return render(request, 'pagenotfound.html', {'path': path}, status="404")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.normpath(expowebpath / path), "r") as o:
|
with open(os.path.normpath(expowebpath / path), "r", encoding='utf-8') as o:
|
||||||
html = o.read()
|
html = o.read()
|
||||||
except:
|
except:
|
||||||
|
# exception raised on debian with python 3.9.2 but not on WSL Ubuntu with python 3.9.5
|
||||||
|
# because debian was assuming default text encoding was 'ascii'. Now specified explicitly so should be OK
|
||||||
try:
|
try:
|
||||||
with open(os.path.normpath(expowebpath / path), "rb") as o:
|
with open(os.path.normpath(expowebpath / path), "rb") as o:
|
||||||
html = str(o.read()).replace("<h1>","<h1>BAD NON-UTF-8 characters here - ")
|
html = str(o.read()).replace("<h1>","<h1>BAD NON-UTF-8 characters here - ")
|
||||||
html = html.replace("\\n","\n")
|
html = html.replace("\\n","\n")
|
||||||
|
html = html.replace("\\r","")
|
||||||
html = html.replace("\\t","\t")
|
html = html.replace("\\t","\t")
|
||||||
html = html.replace("\\'","\'")
|
html = html.replace("\\'","\'")
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user