#138 Problems with Python 3.3

v2.6
closed-duplicate
Chris Liechti
None
5
2014-10-03
2012-12-30
d4or
No

I'm trying to list all ports with python -m serial.tools.list_ports

This works fine with all version of Pythons (tested 2.7.3 and 3.3.0) as long as there is no /dev/ttyUSB0 device (at least not the one I have).

But as soon as I connect the /dev/ttyUSB0 device to my computer and run the command, I encounter an error with python 3.3:

python3.3 -m serial.tools.list_ports
Traceback (most recent call last):
File "/usr/lib/python3.3/runpy.py", line 160, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python3.3/runpy.py", line 73, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports.py", line 99, in <module>
main()
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports.py", line 83, in main
iterator = sorted(comports())
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 122, in comports
return [(d, describe(d), hwinfo(d)) for d in devices]
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 122, in <listcomp>
return [(d, describe(d), hwinfo(d)) for d in devices]
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 93, in describe
return usb_lsusb_string(sys_usb)
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 71, in usb_lsusb_string
iManufacturer = re_group('iManufacturer\s+\w+ (.+)', desc)
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 44, in re_group
m = re.search(regexp, text)
File "/usr/lib/python3.3/re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object

Python 2.7 works fine though..

This is the lsusb output for my device:

Bus 002 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x067b Prolific Technology, Inc.
idProduct 0x2303 PL2303 Serial Port
bcdDevice 3.00
iManufacturer 1 Prolific Technology Inc.
iProduct 2 USB-Serial Controller
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 39
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x000a 1x 10 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0000
(Bus Powered)

Discussion

  • alecjw
    alecjw
    2013-06-10

    Hi, I have the same problem here on arch.
    Lists serial ports fine without my USB-RS232 adaptor plugged in:
    Tartarus% python3 -m serial.tools.list_ports
    /dev/ttyS0
    /dev/ttyS1
    /dev/ttyS2
    /dev/ttyS3
    4 ports found

    But with it:
    Tartarus% python3 -m serial.tools.list_ports
    Traceback (most recent call last):
    File "/usr/lib/python3.3/runpy.py", line 160, in _run_module_as_main
    "main", fname, loader, pkg_name)
    File "/usr/lib/python3.3/runpy.py", line 73, in _run_code
    exec(code, run_globals)
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports.py", line 99, in <module>
    main()
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports.py", line 83, in main
    iterator = sorted(comports())
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 122, in comports
    return [(d, describe(d), hwinfo(d)) for d in devices]
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 122, in <listcomp>
    return [(d, describe(d), hwinfo(d)) for d in devices]
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 93, in describe
    return usb_lsusb_string(sys_usb)
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 71, in usb_lsusb_string
    iManufacturer = re_group('iManufacturer\s+\w+ (.+)', desc)
    File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 44, in re_group
    m = re.search(regexp, text)
    File "/usr/lib/python3.3/re.py", line 161, in search
    return _compile(pattern, flags).search(string)
    TypeError: can't use a string pattern on a bytes-like object

    But again works ok in python2.

    Tartarus% lsusb -vs 21

    Bus 001 Device 021: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
    Couldn't open device, some information will be missing
    Device Descriptor:
    bLength 18
    bDescriptorType 1
    bcdUSB 1.10
    bDeviceClass 0 (Defined at Interface level)
    bDeviceSubClass 0
    bDeviceProtocol 0
    bMaxPacketSize0 64
    idVendor 0x10c4 Cygnal Integrated Products, Inc.
    idProduct 0xea60 CP210x UART Bridge / myAVR mySmartUSB light
    bcdDevice 1.00
    iManufacturer 1
    iProduct 2
    iSerial 3
    bNumConfigurations 1
    Configuration Descriptor:
    bLength 9
    bDescriptorType 2
    wTotalLength 32
    bNumInterfaces 1
    bConfigurationValue 1
    iConfiguration 0
    bmAttributes 0x80
    (Bus Powered)
    MaxPower 100mA
    Interface Descriptor:
    bLength 9
    bDescriptorType 4
    bInterfaceNumber 0
    bAlternateSetting 0
    bNumEndpoints 2
    bInterfaceClass 255 Vendor Specific Class
    bInterfaceSubClass 0
    bInterfaceProtocol 0
    iInterface 2
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x81 EP 1 IN
    bmAttributes 2
    Transfer Type Bulk
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0040 1x 64 bytes
    bInterval 0
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x01 EP 1 OUT
    bmAttributes 2
    Transfer Type Bulk
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0040 1x 64 bytes
    bInterval 0
    Tartarus%

    Tartarus% python --version
    Python 3.3.2
    Tartarus% python2 --version
    Python 2.7.5
    Tartarus%

    Pyserial version is 2.6

     
  • Chris Liechti
    Chris Liechti
    2013-10-12

    This is a duplicate of [#136]

     

    Related

    Bugs: #136

  • Chris Liechti
    Chris Liechti
    2013-10-12

    • status: open --> closed-duplicate
    • assigned_to: Chris Liechti
    • Group: --> v2.6