bleak: bleak.exc.BleakDBusError: [org.bluez.Error.Failed] le-connection-abort-by-local

  • bleak version: 0.16.0
  • Python version: 3.10
  • Operating System: Home Assistant docker container Linux homeassistant 5.15.32-v8 #1 SMP PREEMPT Tue Aug 16 14:52:58 UTC 2022 aarch64 Linux
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.64

Description

Cant connect to device

What I Did

import asyncio
import binascii
import uuid
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError

MAC = "00:A0:50:82:75:CA"
NAME_CHARACTERISTIC = '00002A00-0000-1000-8000-00805F9B34FB'
GENERAL_SERVICE = '00001801-0000-1000-8000-00805f9b34fb'

async def main(ble_address: str):
    device = await BleakScanner.find_device_by_address(ble_address, timeout=20.0)
    async with BleakClient(device) as client:
        services = await client.get_services()
        print("Services:")
        for service in services:
            print(service)
        value = bytes(await client.read_gatt_char(uuid.UUID(NAME_CHARACTERISTIC))).decode('utf-8')
        print(value)

asyncio.run(main(MAC))

The stack-trace is:

Traceback (most recent call last):
  File "/config/./debug_bleak.py", line 29, in <module>
    asyncio.run(main(MAC))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/config/./debug_bleak.py", line 21, in main
    async with BleakClient(device) as client:
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/client.py", line 61, in __aenter__
    await self.connect()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 167, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 24, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] le-connection-abort-by-local

Same code at the native Linux works correctly

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 27 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue on x86 Ubuntu 22.04.1

user@quieter3-01:~/bleak-ble$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
user@quieter3-01:~/bleak-ble$ uname -a
Linux quieter3-01 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
user@quieter3-01:~/bleak-ble$ bluetoothctl -v
bluetoothctl: 5.64
user@quieter3-01:~/bleak-ble$ pip3 show bleak
Name: bleak
Version: 0.19.0
Summary: Bluetooth Low Energy platform Agnostic Klient
Home-page: https://github.com/hbldh/bleak
Author: Henrik Blidh
Author-email: henrik.blidh@nedomkull.com
License: MIT
Location: /home/user/.local/lib/python3.10/site-packages
Requires: async-timeout, dbus-fast
Required-by: