From 637183b1e4aa35a0ad3c4cfb2b0d1d2d71657b97 Mon Sep 17 00:00:00 2001 From: Gert Vervoort Date: Wed, 5 Feb 2020 22:22:58 +0100 Subject: [PATCH 1/2] Python 3.7 pyserial fix: unicode strings are not supported, please encode to bytes [gert@mars bc125csv]$ echo -en "PRG\nBLT,AO\nEPG" | bc125csv shell Traceback (most recent call last): File "/usr/local/bin/bc125csv", line 11, in load_entry_point('bc125csv==1.0.1', 'console_scripts', 'bc125csv')() File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/handler.py", line 386, in main File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/handler.py", line 182, in handle File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/handler.py", line 286, in command_shell File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/handler.py", line 220, in get_scanner File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/scanner.py", line 149, in get_model File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/scanner.py", line 120, in send File "/usr/local/lib/python3.7/site-packages/bc125csv-1.0.1-py3.7.egg/bc125csv/scanner.py", line 115, in writeread File "/usr/lib/python3.7/site-packages/serial/serialposix.py", line 532, in write d = to_bytes(data) File "/usr/lib/python3.7/site-packages/serial/serialutil.py", line 63, in to_bytes raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq)) TypeError: unicode strings are not supported, please encode to bytes: 'MDL\r' [gert@mars bc125csv]$ --- bc125csv/scanner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bc125csv/scanner.py b/bc125csv/scanner.py index 55d5a58..aad278d 100644 --- a/bc125csv/scanner.py +++ b/bc125csv/scanner.py @@ -112,7 +112,7 @@ def __init__(self, port, baudrate=9600): # pragma: no cover super(Scanner, self).__init__(port=port, baudrate=baudrate) def writeread(self, command): # pragma: no cover - self.write(command + "\r") + self.write((command + "\r").encode()) self.flush() return self.readlinecr() @@ -129,7 +129,7 @@ def readlinecr(self): # pragma: no cover """ line = "" while True: - c = self.read(1) + c = self.read(1).decode() if c == "\r": return line line += c From f857f21ac104bf345b0070b2f7b522d231ff51be Mon Sep 17 00:00:00 2001 From: Gert Vervoort Date: Thu, 6 Feb 2020 20:26:34 +0100 Subject: [PATCH 2/2] add Python 3.7 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6b3d8f8..eb577f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: python python: -# Just these two versions for now +# Just these versions for now - "2.7" - "3.4" + - "3.7" install: - python setup.py install # Install coverage for nosetests