Error doing job task exception was never retrieved

The problem Receiving this error in the logs. Probably a coincidence, but may have started around the time I moved from RPi 4 to Odroid N2+ 2021-09-28 09:06:29 ERROR (MainThread) [homeassistant] Er...

The problem

Receiving this error in the logs.
Probably a coincidence, but may have started around the time I moved from RPi 4 to Odroid N2+

2021-09-28 09:06:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 80, in _async_on_connect
await self.async_connect_callback()
File "/usr/src/homeassistant/homeassistant/components/ssdp/__init__.py", line 213, in async_scan
listener.async_search()
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 62, in async_search
assert self._transport is not None
AssertionError

What is version of Home Assistant Core has the issue?

2021.9.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Unsure

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

I don’t believe I’m running anything that has upnp or ssdp

Здравствуйте, я создаю бота и в качестве инструмента использую aiogram.

Вот его исходный код:

from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor

from aiogram.types import ReplyKeyboardMarkup, KeyboardButton

from bs4 import BeautifulSoup
import requests

from telegraph import Telegraph
import aiogram

# from Engine import Parser

TOKEN = '5168757710:AAEMKuCMCsi4ww7Yw8ye-GX44VM4aqET2l8'
Channel_id = '@bebrochka_bts'

bot = Bot(token=TOKEN)
dp = Dispatcher(bot)

btn1 = KeyboardButton('/Github')
btn2 = KeyboardButton('/Telegram')
mainMenu = ReplyKeyboardMarkup(resize_keyboard=True).add(btn1, btn2)


@dp.message_handler(commands=['start'])
async def start(message: types.Message):
    await bot.send_message(message.from_user.id, 'Привет ;)', reply_markup=mainMenu)


@dp.message_handler(commands=['habr_parse'], content_types=['text'])
async def habr_parse(message: types.Message):
    URL = message.get_args()
    
    page = requests.get(URL)

    with open('E:/nohomolawwbaby.p/Python/JetArticles/Article/page.html', 'w', encoding='utf-8') as file:
        file.write(page.text)

    with open('E:/nohomolawwbaby.p/Python/JetArticles/Article/page.html', encoding='utf-8') as file:
        src = file.read()

    soup = BeautifulSoup(src, 'lxml')
    post = soup.find("article", class_="tm-article-presenter__content tm-article-presenter__content_narrow")
    title = post.find("h1", class_="tm-article-snippet__title tm-article-snippet__title_h1").text

    article = open('E:/nohomolawwbaby.p/Python/JetArticles/Article/article.txt', 'w', encoding='utf-8')

    text = post.find_all(['p', 'h4'])

    for i in text:
        article.write(f'{i}nn')

    article.close()

    telegraph = Telegraph()
    telegraph.create_account(short_name='1337')

    with open('E:/nohomolawwbaby.p/Python/JetArticles/Article/article.txt', encoding='utf-8') as f:
        response = telegraph.create_page(
            title,
            html_content=f.read()
        )

        url = 'http://telegra.ph/{}'.format(response['path'])
        msg = f'{title}nn{url}'

        await bot.send_message(message.from_user.id, msg, parse_mode='HTML')


@dp.message_handler(commands=['Github'], content_types=['text'])
async def githublnk(message: types.Message):
    await bot.send_message(message.from_user.id, 'www.example.com')


@dp.message_handler(commands=['Telegram'], content_types=['text'])
async def telegramlnk(message: types.Message):
    await bot.send_message(message.from_user.id, 'www.example.com')


if __name__=='__main__':
    executor.start_polling(dp, skip_updates=True)

Он парсит статью на habr.com и далее пересылает её в telegraph
Но при вводе команды habr_parse бот выдаёт такую ошибку:

Updates were skipped successfully.
Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at E:nohomolawwbaby.pPythonJetArticlesvenvlibsite-packagesaiogramdispatcherdispatcher.py:407> exception=TypeError("object str can't be used in 'await' expression")>
Traceback (most recent call last):
  File "E:nohomolawwbaby.pPythonJetArticlesvenvlibsite-packagesaiogramdispatcherdispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "E:nohomolawwbaby.pPythonJetArticlesvenvlibsite-packagesaiogramdispatcherdispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "E:nohomolawwbaby.pPythonJetArticlesvenvlibsite-packagesaiogramdispatcherhandler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "E:nohomolawwbaby.pPythonJetArticlesvenvlibsite-packagesaiogramdispatcherdispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "E:nohomolawwbaby.pPythonJetArticlesvenvlibsite-packagesaiogramdispatcherhandler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "E:nohomolawwbaby.pPythonJetArticlesbot.py", line 33, in habr_parse
    URL = await message.get_args()
TypeError: object str can't be used in 'await' expression

Что мне делать???

I am following this tutorial (https://www.youtube.com/watch?v=0N_587XCWd0) in order to use my Android device as an IoT Server. After doing some changes like installing libcap, pillow (8.1.2), etc. I then finally deleted home-assistant_v2.db because it gave me these error messages:

1|hass  | 2021-05-10 22:03:23 WARNING (Recorder) [homeassistant.components.recorder.util] The system could not validate that the sqlite3 database at //data/data/com.termux/files/home/.homeassistant/home-assistant_v2.db was shutdown cleanly
1|hass  | 2021-05-10 22:03:23 WARNING (Recorder) [homeassistant.components.recorder.util] Ended unfinished session (id=2 from 2021-05-10 19:58:59.400018)
1|hass  | 2021-05-10 22:04:40 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: http, input_datetime, timer, input_number, system_health, scene, scene.homeassistant, media_source, counter, zone, tag, input_select, input_text, input_boolean, group, logbook

After then deleting home-assistant_v2.db I now get different error messages:

1|hass  | 2021-05-11 01:39:53 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
1|hass  | Traceback (most recent call last):
1|hass  |   File "/data/data/com.termux/files/home/homeassistant/lib/python3.9/site-packages/homeassistant/components/dhcp/__init__.py", line 200, in async_discover
1|hass  |     for host in await self._discover_hosts.async_discover():
1|hass  |   File "/data/data/com.termux/files/home/homeassistant/lib/python3.9/site-packages/aiodiscover/discovery.py", line 144, in async_discover
1|hass  |     await loop.run_in_executor(None, sys_network_data.setup)
1|hass  |   File "/data/data/com.termux/files/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
1|hass  |     result = self.fn(*self.args, **self.kwargs)
1|hass  |   File "/data/data/com.termux/files/home/homeassistant/lib/python3.9/site-packages/aiodiscover/network.py", line 138, in setup
1|hass  |     resolvers = load_resolv_conf()
1|hass  |   File "/data/data/com.termux/files/home/homeassistant/lib/python3.9/site-packages/aiodiscover/network.py", line 39, in load_resolv_conf
1|hass  |     with open("/etc/resolv.conf", "r") as file:
1|hass  | FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'

Issue

Lets assume I have a simple code:

import asyncio


async def exc():
    print(1 / 0)


loop = asyncio.get_event_loop()

loop.create_task(exc())

try:
    loop.run_forever()
except KeyboardInterrupt:
    loop.stop()
    loop.close()

If I run it, I get error message immediately

Task exception was never retrieved
future: <Task finished coro=<exc() done, defined at qq.py:4> exception=ZeroDivisionError('division by zero',)>
Traceback (most recent call last):
  File "qq.py", line 5, in exc
    print(1 / 0)
ZeroDivisionError: division by zero

But, if I change loop.create_task(exc()) to task = loop.create_task(exc())

I’ll get the same error message after click ctrl+c

Why does task assignment change the time of output of error?

Solution

A Exception in the Task (of underlying asyncio.Future to be precise) can be retrieved with Future.exception(). If it’s not retrieved, the exception will be handled at release of the Future object with eventloop’s call_exception_handler.

So, as @dirn pointed, while the Task has reference (assigned to variable in your case) it’s not going be freed, therefore del task_future won’t be called, loop’s handler won’t be executed either.

Answered By — kwarunek

brywithawhy opened this issue a year ago · comments

The problem

Receiving this error in the logs.
Probably a coincidence, but may have started around the time I moved from RPi 4 to Odroid N2+

2021-09-28 09:06:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 80, in _async_on_connect
await self.async_connect_callback()
File "/usr/src/homeassistant/homeassistant/components/ssdp/__init__.py", line 213, in async_scan
listener.async_search()
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 62, in async_search
assert self._transport is not None
AssertionError

What is version of Home Assistant Core has the issue?

2021.9.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Unsure

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

I don’t believe I’m running anything that has upnp or ssdp

I’m affected too.

@brywithawhy I’m using RPi 4, so your move to Odroid is probably really just a coincidence.

Same error here, I’m using hassio vm. Can provide details if you point me in the right direction!

had the issue for a while here too — Home Assistant running in an ESXi VM — happens on every reboot

from what i can see it may be happening becase of some bad ipv6 addresses ? the error happens just after the below warnings (and also happens 3 times)

2021-10-06 09:01:59 WARNING (MainThread) [homeassistant.components.ssdp] Failed to setup listener for fe80::4db5:29db:ead9:f536: [Errno 22] Invalid argument
2021-10-06 09:01:59 WARNING (MainThread) [homeassistant.components.ssdp] Failed to setup listener for fe80::42:3ff:fef9:cd42: [Errno 22] Invalid argument
2021-10-06 09:01:59 WARNING (MainThread) [homeassistant.components.ssdp] Failed to setup listener for fe80::42:1bff:fecd:7955: [Errno 22] Invalid argument

I don’T see those error tho, mine are similar to the one described by @brywithawhy

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 80, in _async_on_connect
    await self.async_connect_callback()
  File "/usr/src/homeassistant/homeassistant/components/ssdp/__init__.py", line 213, in async_scan
    listener.async_search()
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 62, in async_search
    assert self._transport is not None
AssertionError

I don’T see those error tho, mine are similar to the one described by @brywithawhy

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 80, in _async_on_connect await self.async_connect_callback() File "/usr/src/homeassistant/homeassistant/components/ssdp/__init__.py", line 213, in async_scan listener.async_search() File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 62, in async_search assert self._transport is not None AssertionError

I have the same error too — the WARNING messages appear in the log just before the ERROR

had the issue for a while here too — Home Assistant running in an ESXi VM — happens on every reboot

@kingy444, is this a Windows VM or a Linux VM?

I’m uncertain if this will give the information needed, but lets give it a try. Can you enable logging of the ssdp component and async-upnp-client, by adding this to your configuration.yaml:

logger:
  default: warning
  logs:
    async_upnp_client: debug
    async_upnp_client.traffic: error
    homeassistant.components.ssdp: debug

Please upload a file (feel free to redact any sensitive information if you feel so) from the logging. Afterwards, you can remove the added part again from your configuration.

logs.txt
This was captured right at the start of a system restart — not sure there is anything useful there
the logs definitely get flooded with SSDP events once the system is up and running, but the errors had already presented by that time

What a classical situation. The AssertionError hasn’t happened to me since enabling debugging log output. 😅

I have similar errors, flooding my logs since quite a while now:

Logger: homeassistant
Source: /usr/src/homeassistant/homeassistant/runner.py:90
First occurred: 14:09:20 (224 occurrences)
Last logged: 16:00:21
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 83, in _async_on_data
    await self.async_callback(headers)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/ssdp_listener.py", line 392, in _on_search
    ) = self._device_tracker.see_search(headers)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/ssdp_listener.py", line 156, in see_search
    udn = headers["_udn"]
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/utils.py", line 57, in __getitem__
    return self._data[self._case_map[key.lower()]]
KeyError: '_udn'

Are you running the latest (released) version of home assistant, @birdie60?

@kingy444, these lines are worrisome:

2021-10-12 11:00:07 DEBUG (MainThread) [async_upnp_client.ssdp] Connection made, transport: None
2021-10-12 11:00:07 DEBUG (MainThread) [async_upnp_client.ssdp] Connection made, transport: None
2021-10-12 11:00:07 DEBUG (MainThread) [async_upnp_client.ssdp] Connection made, transport: None

I’m wondering if these would be for IPv6, or for IPv4, or are not related at all.

Combined with these lines:

2021-10-12 11:00:07 DEBUG (MainThread) [async_upnp_client.ssdp] Skipping setting multicast interface
2021-10-12 11:00:07 DEBUG (MainThread) [async_upnp_client.ssdp] Skipping setting multicast interface
2021-10-12 11:00:07 DEBUG (MainThread) [async_upnp_client.ssdp] Skipping setting multicast interface

And these as well:

2021-10-12 11:00:07 WARNING (MainThread) [homeassistant.components.ssdp] Failed to setup listener for fe80::42:2eff:fe90:52b2: [Errno 22] Invalid argument
2021-10-12 11:00:07 WARNING (MainThread) [homeassistant.components.ssdp] Failed to setup listener for fe80::4db5:29db:ead9:f536: [Errno 22] Invalid argument
2021-10-12 11:00:07 WARNING (MainThread) [homeassistant.components.ssdp] Failed to setup listener for fe80::42:79ff:fe3f:75a: [Errno 22] Invalid argument

I’m not using IPv6 on my own network. Hopefully I can easily enable this and reproduce it.

Are you running the latest (released) version of home assistant, @birdie60?

@StevenLooman: I am running Home Assistant 2021.10.0.

@birdie60, the traceback is similar to #57015. Can you update to
2021.10.6 and verify the issue is still occurring?

I’m on Home Assistant 2021.10.6 now, and the issue seems to be gone. Heureka!
Thanks a lot, @StevenLooman!

Just chiming in that I am running 2021.10.6 and still have the issue

Didn’t expect your issue to be fixed @kingy444, but thank you for the update. I plan to soon investigate this further.

I am able to reproduce it (or at least something similar), now a fix…

Ok, the problem is that to bind a IPv6 multicast socket (used for SSDP), a so called ‘scope_id’ is needed. This scope_id is available in home assistant, see

sources.extend(IPv6Address(ipv6[«address»]) for ipv6 in adapter[«ipv6»])

But in Python3.8 the IPv6Address does not provide a means to store the scope_id, while IPv6Address in Python3.9 does provide it. There is even a comment in the home assistant source stating how to use it! :)

Python3.8 support will be dropped 2022.1. Either we wait and do a small change then, or do a hack now to work around this.

The hack I had in mind does not work, unfortunately. I’ll try some more but I can’t promise anything. The best bet so far is to wait for 2022.1.

Still working on this, though progress is slow due to other things requiring some time.

Still working on this, though progress is slow due to other things requiring some time.

Only a warning, sure we can live with it for a little — and 2022-1 isn’t too far — I say as long as this issue can remain open and not auto close tackle it in the new year 😉

There hasn’t been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Please don’t close yet, fix on the way.

The problem

Logger: homeassistant
Source: /usr/src/homeassistant/homeassistant/runner.py:90
First occurred: 19:31:38 (135 occurrences)
Last logged: 19:43:37

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File «/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py», line 83, in _async_on_data
await self.async_callback(headers)
File «/usr/local/lib/python3.9/site-packages/async_upnp_client/ssdp_listener.py», line 392, in _on_search
) = self._device_tracker.see_search(headers)
File «/usr/local/lib/python3.9/site-packages/async_upnp_client/ssdp_listener.py», line 156, in see_search
udn = headers[«_udn»]
File «/usr/local/lib/python3.9/site-packages/async_upnp_client/utils.py», line 57, in getitem
return self._data[self._case_map[key.lower()]]
KeyError: ‘_udn’

What is version of Home Assistant Core has the issue?

2021.10.0

What was the last working version of Home Assistant Core?

supervisor-2021.09.6

What type of installation are you running?

Home Assistant OS

Integration causing the issue

async upnp

Link to integration documentation on our website

https://www.home-assistant.io/integrations/upnp/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

Понравилась статья? Поделить с друзьями:
  • Error document is not defined no undef
  • Error document follows
  • Error docker exporter does not currently support exporting manifest lists
  • Error do not access object prototype method hasownproperty from target object no prototype builtins
  • Error dmg image is corrupted