Tracardi / imap-bridge

Monitors IMAP
0 stars 2 forks source link

Error: asyncio.exceptions.CancelledError email_checker.py line 49 #4

Closed bobsburgers closed 2 months ago

bobsburgers commented 2 years ago

best I can tell is the loop is getting canceled before it gets anyplace. But i have found no clue as to why. Running python 3.10 wsl ubuntu/windows. And git pull of tracardi-api and tracardi master (dont think that is part of the issue though). asyncio.exceptions.CancelledError

try:
    self.client = aioimaplib.IMAP4_SSL(host=self.host, port=self.port)
except ssl.SSLError:
    self.client = aioimaplib.IMAP4(host=self.host, port=self.port)
await self.client.wait_hello_from_server()

/root/.virtualenvs/imap-bridge/lib/python3.10/site-packages/elasticsearch/connection/base.py:193: ElasticsearchDeprecationWarning: Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.13/security-minimal-setup.html to enable security.
  warnings.warn(message, category=ElasticsearchDeprecationWarning)
INFO:elasticsearch:POST http://127.0.0.1:9200/_bulk [status:200 request:0.043s]
INFO:elasticsearch:POST http://127.0.0.1:9200/eb836.tracardi-source/_refresh [status:200 request:0.036s]
INFO:app.service.main_loop:IMAP Bridge registered with id 71e659fc-d0ac-40bb-aada-8ba73f0baa92 as IMAP
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-10' coro=<BaseEventLoop.create_connection() done, defined at /usr/lib/python3.10/asyncio/base_events.py:975> exception=SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)')>
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1092, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1122, in _create_connection_transport
    await waiter
  File "/usr/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/usr/lib/python3.10/ssl.py", line 975, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)
Traceback (most recent call last):
  File "/mnt/d/Programing/tracardi/imap-bridge/app/service/main_loop.py", line 39, in main
    await coro(self._shut_down)
  File "/mnt/d/Programing/tracardi/imap-bridge/app/start.py", line 22, in run_bridge
    checker = await EMailChecker.connect()
  File "/mnt/d/Programing/tracardi/imap-bridge/app/bridge/email_checker.py", line 42, in connect
    await checker.start()
  File "/mnt/d/Programing/tracardi/imap-bridge/app/bridge/email_checker.py", line 89, in start
    self.client = await self.get_client_logged_in()  # type: aioimaplib.IMAP4 or aioimaplib.IMAP4_SSL
  File "/mnt/d/Programing/tracardi/imap-bridge/app/bridge/email_checker.py", line 50, in get_client_logged_in
    await self.client.wait_hello_from_server()
  File "/root/.virtualenvs/imap-bridge/lib/python3.10/site-packages/aioimaplib/aioimaplib.py", line 694, in wait_hello_from_server
    await asyncio.wait_for(self.protocol.wait('AUTH|NONAUTH'), self.timeout)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 432, in wait_for
    await waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/d/Programing/tracardi/imap-bridge/app/start.py", line 55, in <module>
    MainLoop(run_bridge, event_source)
  File "/mnt/d/Programing/tracardi/imap-bridge/app/service/main_loop.py", line 24, in __init__
    loop.run_until_complete(self.main_task)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
asyncio.exceptions.CancelledError
python-BaseException
bobsburgers commented 2 years ago

Tested with 3.9 and still getting the same error.

bobsburgers commented 2 years ago

Ok its 2 issues. 1 an issue with connecting with a server. Any issue really seems to be able to call it. I have found that there is an issue with passing the error along someplace around the code below. main_loop.py line 41 def _exception_handler(self, loop, context): loop.default_exception_handler(context) self.main_task.cancel()

You can see the real error there and it starts another exception that the future has been canceled. It makes it impossible to use try: except several types of errors.

I have not yet looked into the issue or how to pass the data or prevent the other exception