'NoneType' object has no attribute 'delegate' exception when connecting
See original GitHub issue- bleak version: 0.8.0
- Python version: Python 3.7.4
- Operating System: macOS 10.15.2 (Catalina)
Description
I’m trying to write an application that uses tkinter and bleak to discover and interact with a custom BLE device. However, when I try to connect to the device, it throws an exception:
'NoneType' object has no attribute 'delegate'
File ".../scratch.py", line 29, in run
await client.connect()
File ".../miniconda3/envs/py3/lib/python3.8/site-packages/bleak/backends/corebluetooth/client.py", line 86, in connect
manager = self._device_info.manager().delegate()
(There is also a similar exception thrown in the final clause when attempting to disconnect)
I have condensed this to the application shown below.
import asyncio
import re
import traceback
import tkinter as tk
from bleak import BleakClient
from bleak import BleakScanner
async def run():
if explicit:
devices = await BleakScanner.discover(loop=loop)
else:
devices = await BleakScanner.discover()
for d in devices:
print(d)
matcher = re.compile(r"[A-z]{3}-[0-9]{3}")
devices = [d for d in devices if matcher.match(d.name)]
if explicit:
client = BleakClient(devices[0].address, loop=loop)
else:
client = BleakClient(devices[0].address)
try:
if explicit:
await client.connect(loop=loop)
else:
await client.connect()
print("Connected to {0}".format(client))
except Exception as e:
print(e)
traceback.print_tb(e.__traceback__)
finally:
await client.disconnect()
def scan_and_connect():
asyncio.get_event_loop().create_task(run())
async def update_ui():
while True:
root.update()
await asyncio.sleep(1 / 30)
explicit = False # Explicit or implicit run loops
loop = asyncio.get_event_loop()
root = tk.Tk()
if explicit:
root.loop = loop
btn = tk.Button(root, text="Scan and connect", command=scan_and_connect)
btn.grid(column=1, row=1)
loop.run_until_complete(update_ui())
# Works as expected (i.e. connects to device)
# loop.run_until_complete(run())
What I Did
I’ve tried the following combinations:
Bleak | Loop | Outcome |
---|---|---|
v0.7.1 | Implicit | Exception |
v0.7.1 | Explicit | Exception |
v0.8.0 | Implicit | Exception |
v0.8.0 | Explicit | Exception |
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
python - AttributeError: 'NoneType' object has no attribute ' ...
AttributeError : 'NoneType' object has no attribute 'setDelegate_'. is the full error message. My code is below.
Read more >AttributeError: 'NoneType' object has no attribute 'call' on ...
Hello, I'm at a loss to explain why this flow fails and succeeds at the same time… It only consists in triggering a...
Read more >Attributeerror: 'Nonetype' Object Has No Attribute '_Root'
The AttributeError: 'NoneType' object has no attribute 'append' error happens when the append attribute is called in the None type object. The NoneType....
Read more >Ticket: User Preferences throws AttributeError: 'NoneType' ...
It's simply because there is no attribute with the name you called, for that Object. This means that you got the error when...
Read more >Issue 17613: IDLE "AttributeError: 'NoneType' object has no ...
... in __getattr__ attr = getattr(self.delegate, name) # May raise AttributeError AttributeError: 'NoneType' object has no attribute 'index'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Works perfectly! 👌 Both connecting and disconnecting works with tkinter now. I’ll continue testing next week with reading, writing and notifications.
Thanks @0ge and @Carglglz for all of the investigation and testing to get to the bottom of the issue!