From 1838403e3b87dac56678107955625cc7ca09e4d6 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Mon, 22 Oct 2018 15:59:12 +0100 Subject: [PATCH] [#3199|Console] Fix UnicodeEncodeError in addstr The following error was encountered by user: ...deluge/ui/console/modes/basemode.py, line 290, in add_string screen.addstr(row, col, string, color) UnicodeEncodeError: 'ascii' codec can't encode character... The `add_str` method is defaulting to using the Python 2 ascii encoding with a unicode string so use the encoding passed to the function. --- deluge/ui/console/modes/basemode.py | 2 +- deluge/ui/console/modes/cmdline.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deluge/ui/console/modes/basemode.py b/deluge/ui/console/modes/basemode.py index 6ad2a2c36..d3b3e5754 100644 --- a/deluge/ui/console/modes/basemode.py +++ b/deluge/ui/console/modes/basemode.py @@ -299,7 +299,7 @@ def add_string( string = string[0:remaining_chrs] try: - screen.addstr(row, col, string, color) + screen.addstr(row, col, string.encode(encoding), color) except curses.error as ex: # Ignore exception for writing offscreen. pass diff --git a/deluge/ui/console/modes/cmdline.py b/deluge/ui/console/modes/cmdline.py index 21236c3c7..de0d7432b 100644 --- a/deluge/ui/console/modes/cmdline.py +++ b/deluge/ui/console/modes/cmdline.py @@ -548,7 +548,7 @@ class CmdLine(BaseMode, Commander): # This is the last string so lets append some " " to it s += ' ' * (self.cols - (col + strwidth(s)) - 1) try: - self.stdscr.addstr(row, col, s, color) + self.stdscr.addstr(row, col, s.encode(self.encoding), color) except curses.error: pass