Skip to content

Commit bad0d3e

Browse files
committed
Properly handle filsystem character encoding when showing warnings
Fix #14567
1 parent c59350a commit bad0d3e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

python/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@
6565

6666

6767
def showWarning(message, category, filename, lineno, file=None, line=None):
68-
stk = ""
69-
for s in traceback.format_stack()[:-2]:
70-
stk += s.decode('utf-8', 'replace') if hasattr(s, 'decode') else s
68+
stk = ''.join([s.decode(sys.getfilesystemencoding()) for s in traceback.format_stack()[:-2]])
7169
QgsMessageLog.logMessage(
72-
"warning:%s\ntraceback:%s" % (warnings.formatwarning(message, category, filename, lineno), stk),
70+
u"warning:{}\ntraceback:{}".format(warnings.formatwarning(message, category, filename.decode(sys.getfilesystemencoding()), lineno), stk),
7371
QCoreApplication.translate("Python", "Python warning")
7472
)
7573

0 commit comments

Comments
 (0)