From 9ff7d2c5a70298da885e5917b39f79cccb16dbaa Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 8 Nov 2019 15:10:54 +0100 Subject: [PATCH] transactions (qt): fix opening raw bytes files (both when trying to "load tx from file", and "load tx from text" > "browse file") --- electrum/gui/qt/main_window.py | 2 +- electrum/gui/qt/qrtextedit.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 704be55db..9f7d0da1f 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2755,7 +2755,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): if not fileName: return try: - with open(fileName, "r") as f: + with open(fileName, "rb") as f: file_content = f.read() # type: Union[str, bytes] except (ValueError, IOError, os.error) as reason: self.show_critical(_("Electrum was unable to open your transaction file") + "\n" + str(reason), diff --git a/electrum/gui/qt/qrtextedit.py b/electrum/gui/qt/qrtextedit.py index 9cfc3e301..dfef17454 100644 --- a/electrum/gui/qt/qrtextedit.py +++ b/electrum/gui/qt/qrtextedit.py @@ -47,8 +47,13 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin): if not fileName: return try: - with open(fileName, "r") as f: - data = f.read() + try: + with open(fileName, "r") as f: + data = f.read() + except UnicodeError as e: + with open(fileName, "rb") as f: + data = f.read() + data = data.hex() except BaseException as e: self.show_error(_('Error opening file') + ':\n' + repr(e)) else: