MerossIot: RuntimeError: There is no current event loop in thread 'Thread-1'
π Iβm trying to run the demo code from the docs. Iβve done the following:
$ python3 --version
Python 3.8.5
$ python3 -m venv .env
$ source .env/bin/activate
$ pip install meross-iot --upgrade --no-cache
$ pbpaste > main.py
$ # ... Edit the email and password
$ python main.py
Hereβs the content of the python file, sans credentials:
main.py
import asyncio
import os
from meross_iot.http_api import MerossHttpClient
from meross_iot.manager import MerossManager
EMAIL = os.environ.get('MEROSS_EMAIL') or "XXX"
PASSWORD = os.environ.get('MEROSS_PASSWORD') or "XXX"
async def main():
# Setup the HTTP client API from user-password
http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)
# Setup and start the device manager
manager = MerossManager(http_client=http_api_client)
await manager.async_init()
# Discover devices.
await manager.async_device_discovery()
meross_devices = manager.find_devices()
# Print them
print("I've found the following devices:")
for dev in meross_devices:
print(f"- {dev.name} ({dev.type}): {dev.online_status}")
# Close the manager and logout from http_api
manager.close()
await http_api_client.async_logout()
if __name__ == '__main__':
# On Windows + Python 3.8, you should uncomment the following
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
And the resulting error logs. Weirdly, it can see my devices, but unable to read or control them:
stdout
INFO:Initializing the MQTT connection...
INFO:Subscribed to topics, updating state for already known devices...
INFO:
------- Triggering HTTP discovery, filter_device: None -------
INFO:The following devices were already known to me: {}
INFO:The following devices are new to me: [<meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76f40>, <meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76d60>, <meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76d90>, <meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76e50>, <meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76df0>, <meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76eb0>, <meross_iot.model.http.device.HttpDeviceInfo object at 0x10dc76f70>]
INFO:Updating 0 known devices form HTTPINFO and fetching data from 7 newly discovered devices...
INFO:Could not retrieve abilities for device Bed plug (1908305402074839089548e1e9511c2a). This device won't be enrolled.
INFO:Could not retrieve abilities for device Vacuum charger (19010823789142251a1334298f146aa0). This device won't be enrolled.
ERROR:Timeout occurred while waiting a response for message b'{"header": {"from": "/app/370946-477270b7d9385da9e9913541aad05092/subscribe", "messageId": "cc6ef0b10f561934303fadd0e52ed0a9", "method": "GET", "namespace": "Appliance.System.Ability", "payloadVersion": 1, "sign": "7e09343847116cee89c853e2309393bd", "timestamp": 1600969659}, "payload": {}}' sent to device uuid 19121877533782251h2848e1e913e310. Timeout was: 5.0 seconds
ERROR:Failed to retrieve abilities for device Main fan (19121877533782251h2848e1e913e310). This device won't be enrolled.
ERROR:Timeout occurred while waiting a response for message b'{"header": {"from": "/app/370946-477270b7d9385da9e9913541aad05092/subscribe", "messageId": "e6dda6dd91d2e57bdb27ee3e34f0558a", "method": "GET", "namespace": "Appliance.System.Ability", "payloadVersion": 1, "sign": "073d5eadfd4838b5ec4292630dd30b4c", "timestamp": 1600969659}, "payload": {}}' sent to device uuid 19121824471830251h2848e1e913e463. Timeout was: 5.0 seconds
ERROR:Failed to retrieve abilities for device Desk fan (19121824471830251h2848e1e913e463). This device won't be enrolled.
ERROR:Timeout occurred while waiting a response for message b'{"header": {"from": "/app/370946-477270b7d9385da9e9913541aad05092/subscribe", "messageId": "53d875535e2d48c5607bc7be0d7cd40d", "method": "GET", "namespace": "Appliance.System.Ability", "payloadVersion": 1, "sign": "8543757cb13c44bd5b315ea7e245ecb8", "timestamp": 1600969659}, "payload": {}}' sent to device uuid 19091244678221251h1848e1e904527f. Timeout was: 5.0 seconds
ERROR:Failed to retrieve abilities for device Control panel (19091244678221251h1848e1e904527f). This device won't be enrolled.
ERROR:Timeout occurred while waiting a response for message b'{"header": {"from": "/app/370946-477270b7d9385da9e9913541aad05092/subscribe", "messageId": "5b139c36ca635ee1a3f80dec9a5b6bc5", "method": "GET", "namespace": "Appliance.System.Ability", "payloadVersion": 1, "sign": "68f6964755c7e64f9cfb3897cd915d22", "timestamp": 1600969659}, "payload": {}}' sent to device uuid 19091228424117251h1848e1e9045294. Timeout was: 5.0 seconds
ERROR:Failed to retrieve abilities for device Living room shelf (19091228424117251h1848e1e9045294). This device won't be enrolled.
ERROR:Timeout occurred while waiting a response for message b'{"header": {"from": "/app/370946-477270b7d9385da9e9913541aad05092/subscribe", "messageId": "bdc91eabcf7b0cacf2150a294bf65129", "method": "GET", "namespace": "Appliance.System.Ability", "payloadVersion": 1, "sign": "658edb4c8c5b6e64d041e66826fbdae0", "timestamp": 1600969659}, "payload": {}}' sent to device uuid 1911115584535990804948e1e9115f50. Timeout was: 5.0 seconds
ERROR:Failed to retrieve abilities for device Desk speakers (1911115584535990804948e1e9115f50). This device won't be enrolled.
INFO:Fetch and update done
INFO:
------- HTTP discovery ended -------
I've found the following devices:
INFO:Disconnecting from mqtt
INFO:MQTT Client has fully disconnected.
INFO:Logout succeeded.
stderr
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 3452, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 1779, in loop_forever
rc = self.loop(timeout, max_packets)
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 1181, in loop
rc = self.loop_read(max_packets)
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 1572, in loop_read
rc = self._packet_read()
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 2310, in _packet_read
rc = self._packet_handle()
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 2944, in _packet_handle
return self._handle_suback()
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/paho/mqtt/client.py", line 3150, in _handle_suback
self.on_subscribe(
File "/Users/danhughes/src/github.com/dan1elhughes/casa/services/service.meross/.env/lib/python3.8/site-packages/meross_iot/manager.py", line 349, in _on_subscribe
results = asyncio.gather(*tasks)
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py", line 749, in gather
loop = events.get_event_loop()
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1'.
Thank you for your time, and for this library π
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 15 (2 by maintainers)
Thanks @christianbrinch !
I was just about to report this issue myself. I have two Raspberry piβs, a model 3 and a model 3B. They both run Python 3.7.3 and meross_iot 0.4.0.3. The script posted above by @dan1elhughes works as expected on the RPi3, but fails with the runtime error on the RPi3B.
EDIT: I just realized that the RPi3 was running paho-mqtt==1.5.0, while the RPi3B has paho-mqtt==1.5.1. Downgrading the installation on the RPi3B to version 1.5.0 solved the problem.