HappyLighting-py icon indicating copy to clipboard operation
HappyLighting-py copied to clipboard

Bleak error

Open ImShEthan opened this issue 1 year ago • 6 comments

Hello, i'm having trouble when scanning, got this error :

libpng warning: iCCP: known incorrect sRGB profile
Traceback (most recent call last):
  File "C:\Users\Tatane\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\qasync\__init__.py", line 780, in _error_handler
    task.result()
  File "C:\Users\Tatane\Downloads\HappyLighting-py-master\LEDStripController\pyhl.py", line 284, in handle_scan
    devices = await BLEClass.BleakScanner.discover(timeout=8.0)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Tatane\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\bleak\__init__.py", line 320, in discover
    async with cls(**kwargs) as scanner:
  File "C:\Users\Tatane\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\bleak\__init__.py", line 158, in __aenter__
    await self._backend.start()
  File "C:\Users\Tatane\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\bleak\backends\winrt\scanner.py", line 222, in start
    assert_mta()
  File "C:\Users\Tatane\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\bleak\backends\winrt\util.py", line 78, in assert_mta
    raise BleakError(
bleak.exc.BleakError: The current thread apartment type is not MTA: STA. Beware of packages like pywin32 that may change the apartment type implicitly.

ImShEthan avatar May 18 '24 18:05 ImShEthan

have you installed requirements via requirements.txt?

MikeCoder96 avatar May 18 '24 19:05 MikeCoder96

have you installed requirements via requirements.txt?

Yeah I did

ImShEthan avatar May 18 '24 19:05 ImShEthan

Tried to replicate it and it happens to me only if I try to press search multiple time. I think that this is not your case right?

MikeCoder96 avatar May 21 '24 22:05 MikeCoder96

Hello, sorry for the long responce, No I don't press the search button multiple times, maybe I don't understand how to use it. I link a gif of the error.

explorer_ZFPoHwfQyQ

ImShEthan avatar May 25 '24 12:05 ImShEthan

This issue usually happens because Bleak needs to run in a Multi Threaded Apartment (MTA); hence, the reason you get the BleakError.

Try adding sys.coinit_flags = 0 after importing sys at the top of the file:

import sys
sys.coinit_flags = 0    # 0 means MTA
# Other packages below

More information on these errors here.

tapiaer22 avatar Sep 16 '24 03:09 tapiaer22

you can make a pull request about it if you want

MikeCoder96 avatar Sep 19 '24 20:09 MikeCoder96