cuzzo/iw_parse

Raspberry Pi

Opened this issue · 1 comments

On RPI 4, I am getting following error,

>>> get_interfaces()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/smartcar-app-v1/lib/iw_parse.py", line 336, in get_interfaces
    return get_parsed_cells(call_iwlist(interface).split('\n'))
TypeError: a bytes-like object is required, not 'str'

apparently the underlying call_iwlist is returning a byte object

>>> print(call_iwlist())
b'wlan0     Scan completed :\n          Cell 01 -...\n\n'

So to fix the issue I just updated the get_interfaces to decode the call_iwlist as following,

def get_interfaces(interface="wlan0"):
    """ Get parsed iwlist output
        @param string interface
            interface to scan
            default is wlan0

        @param list columns
            default data attributes to return

        @return dict
            properties: dictionary of iwlist attributes
    """
    return get_parsed_cells(call_iwlist(interface).decode().split('\n'))

Thanks nbasha! Same issue on RPI4, great solution.