You should not use this code as anything but a possible reference for BLE packets; instead, you should probably use Bleak: https://github.com/hbldh/bleak - it seems to be the modern BLE python client.
Experiments in Bluetooth Low Energy & Python