cuzzo / iw_parse

Parse the output of iwlist scan to get the name, address, quality, channel, and encryption type of all networks broadcasting within your Wireless NIC's reach.
BSD 2-Clause "Simplified" License
30 stars 36 forks source link

Raspberry Pi #13

Open nabsha opened 3 years ago

nabsha commented 3 years ago

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'))
BSBoatia commented 2 years ago

Thanks nbasha! Same issue on RPI4, great solution.