aioblescan: 'NoneType' object is not subscriptable

Hello,

I’m getting 'NoneType' object is not subscriptable error when run python3 -m aioblescan on Debian Bullseye (armv6, Rapberry Pi 1 B+) Python version: 3.9.2 aioblescan: 0.2.10

Here is the stacktrace:

Fatal error: protocol.data_received() call failed.
protocol: <aioblescan.aioblescan.BLEScanRequester object at 0xb61293e8>
transport: <_SelectorSocketTransport fd=6 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 870, in _read_ready__data_received
    self._protocol.data_received(data)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/aioblescan.py", line 1852, in data_received
    self.process(packet)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/__main__.py", line 51, in my_process
    xx = ev.decode(data)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/aioblescan.py", line 1303, in decode
    data = ev.decode(data)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/aioblescan.py", line 1350, in decode
    data = ev.decode(data)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/aioblescan.py", line 833, in decode
    data = field.decode(data)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/aioblescan.py", line 1473, in decode
    data = x.decode(data)
  File "/usr/local/lib/python3.9/dist-packages/aioblescan/aioblescan.py", line 236, in decode
    self._val = unpack(">B", data[:1])[0]
TypeError: 'NoneType' object is not subscriptable

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@shadowsgit Thanks for the PR @Ernst79 new release pushed to PyPi

@Ernst79 me also used its as HA integration, but in my case it somehow works fine without above fix with HA, but it was failed in few seconds when I launch aioblescan as is. (or HA at least restart plugin). To be honest I don’t know how to get similar log from HA as mentioned in https://github.com/custom-components/ble_monitor/issues/433 )) Formally you reported other issue… But looking into official bluez sample make me believe that payload inside #36 is totally correct and it parsing should looks like:

--------------------------------------------------------------------------------------------------------------------------------------------------------------
HCI  Evt Len Sub Num Evt  Peer -------MAC-------   Len  Len Type Val    Len Type Val   Len Type -------Val---------------- RSSI--Evt  Peer -------MAC-------        RSSI
type code    evt rep type addr                              flag            flag           flag
--------------------------------------------------------------------------------------------------------------------------------------------------------------
 04   3e 27  02  02   00   01  96 2f da 31 46 68   11   02   01  1a     02   0a  0c     0a  ff  4c 00 10 05 03 18 f8 89 18   ba   04   01   96 2f da 31 46 68 00    ba

So repro code

import aioblescan as aiobs
ev = aiobs.HCI_Event()
data=bytearray.fromhex("043e2702020001962fda3146681102011a020a0c0aff4c0010050318f88918ba0401962fda31466800ba")
xx = ev.decode(data)
ev.show(0)

And the fix #46:

and correct output:


HCI Event:
    code:
        3e
    length:
        39
    LE Meta:
        code:
            02
        Adv Report: 2
            Adv Report:
                ev type:
                    generic adv
                addr type:
                    random
                peer:
                    68:46:31:da:2f:96
                length:
                    17
                    type:
                        flags
                    flags:
                        Simul LE - BR/EDR (Host): True
                        Simul LE - BR/EDR (Control.): True
                        BR/EDR Not Supported: False
                        LE General Disc.: True
                        LE Limited Disc.: False
                    type:
                        tx_power_level
                    Payload for tx_power_level:
                        0c
                    type:
                        mfg_specific_data
                    Manufacturer Specific Data:
                        Manufacturer ID:
                            76
                        Payload:
                            10:05:03:18:f8:89:18
                rssi:
                    -70
            Adv Report:
                ev type:
                    scan rsp
                addr type:
                    random
                peer:
                    68:46:31:da:2f:96
                length:
                    0
                rssi:
                    -70

As a suggestion for debugging… Have sudo btmon running in a different terminal. That should give you the raw data coming in.