FS#29530 - [python-pyserial] miniterm.py sometimes crashes with UnicodeEncodeError

Attached to Project: Community Packages
Opened by Alexandru Stan (amstan) - Wednesday, 18 April 2012, 19:30 GMT
Last edited by Sergej Pupykin (sergej) - Sunday, 18 August 2013, 11:18 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Sergej Pupykin (sergej)
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
When receiving invalid characters from serial, miniterm.py(the useful demo tool for python-pyserial) crashes. I think this is because miniterm.py is not meant to run in python3(the default python for arch).

Steps to reproduce:
* Open a serial port
* Receive invalid data(I managed to do it by playing with the RX wire, but i think wrong baud rates will also work)
* UnicodeEncodeError: 'ascii' codec can't encode character '\x97' in position 0: ordinal not in range(128)

Logs:
alex@alex-laptop:~% head -n 1 `which miniterm.py`
#!/usr/bin/python
alex@alex-laptop:~% file /usr/bin/python
/usr/bin/python: symbolic link to `python3'
alex@alex-laptop:~% miniterm.py --port /dev/ttyUSB0 --baud 19200 --rts=0 --dtr=0
--- Miniterm on /dev/ttyUSB0: 19200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
--- forcing DTR inactive
--- forcing RTS inactive
Initialization Done.Mosfet 14 192uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 192uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 14 193uA on:1
Mosfet 31 13uA on:1
Initialization Done.SkException in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
self.run()
File "/usr/lib/python3.2/threading.py", line 693, in run
self._target(*self._args, **self._kwargs)
File "/usr/bin/miniterm.py", line 227, in reader
sys.stdout.write(data)
UnicodeEncodeError: 'ascii' codec can't encode character '\x97' in position 0: ordinal not in range(128)

The way I go around this is to use miniterm2(which i think is the same thing with the #! line changed), but it's really annoying having different stuff in makefiles for other OSs. What i suggest is to make python-pyserial(the python3 one) not come with a miniterm.py, and just let the python2-pyserial package take care of it(rename miniterm2.py to miniterm.py).
This task depends upon

Closed by  Sergej Pupykin (sergej)
Sunday, 18 August 2013, 11:18 GMT
Reason for closing:  Fixed
Comment by Alexandru Stan (amstan) - Wednesday, 18 April 2012, 20:12 GMT
I also contacted the main developer(Chris Liechti) for pyserial, perhaps he can fix this bug in the first place and we wouldn't have to worry about making python2-pyserial's miniterm the default.
Comment by Alexander F. Rødseth (xyproto) - Thursday, 25 October 2012, 12:42 GMT
If you can find a place in the code where open() is used to open a file, open(filename, encoding="utf8") may fix this problem, in some cases. If it works, perhaps upstream would like a patch?
Comment by Alexander F. Rødseth (xyproto) - Sunday, 02 December 2012, 14:27 GMT Comment by Jelle van der Waa (jelly) - Sunday, 18 August 2013, 09:34 GMT
The new version seems to work fine here.

Loading...