Problem after update...
LeOS1971 opened this issue · comments
Describe the bug
since days ago everything worked great.. but I tried to update to latest version and... old code no longer works
To Reproduce
just created the quick start code:
import asyncio
from aiohttp import ClientSession
from blinkpy.blinkpy import Blink
async def start():
blink = Blink(session=ClientSession())
await blink.start()
return blink
blink = asyncio.run(start())
run with: python3 blabla.py
inserted username and password (I'm sure are correct)
get this:
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f8e8ad9b5e0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f8e8adbc7c0>, 109622.30803668)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7f8e8adbd480>, 109624.934089018)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f8e8ad9b670>
really no idea what it means :(
That output is expected- it's just a logging message from aiohttp. Based on that log, everything is working fine. The library has been migrated to asyncio so old code will break and needs to be migrated (like the example code you ran).
a ok infact it works, adding commands I can read infos (stupid me I didn't do more test).
Is there a way to disable this verbose output? I'm using this for automation inserting info on my Domoticz, I'd like to have clear output like old versions.. thanks a lot
There should be but I haven't figured it out yet. It annoys me too, so hopefully I (or someone else) can figure out a solution soon.
A ok :)
at the moment, using it with a bash wrapper, I can get output I need simply ignoring annoying messages with:
python blablabla.py 2>&1 |grep whatIneed
on this way it works... I'll see if I'll be able to make it natively.
Cheers, Leo
To stop this error, you need to close the session as can be seen here:
Line 38 in 0c7c3a1
Simply "killing" python will give you an unclosed session error.
@mkmer is on the right track, but the example code blinkapp.py
is broken slightly....
I added debug to my own code, and discovered that while I created the session
object similar to blinkapp.py
line 34
session = ClientSession()
print('--------------------> Created session {}'.format(session))
blink = blinkpy.Blink(session=session)
it would print a line such as:
--------------------> Created session <aiohttp.client.ClientSession object at 0x7ff531cf0cd0>
And then at the end of my code:
print('about to close session {} ------------------------'.format(session))
await session.close()
print('DONE with close session {} ------------------------'.format(session))
When I ran, it printed this, convincing me that there were TWO SESSIONS being created:
about to close session <aiohttp.client.ClientSession object at 0x7ff531cf0cd0> ------------------------
DONE with close session <aiohttp.client.ClientSession object at 0x7ff531cf0cd0> ------------------------
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7ff531cf0d00>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7ff531cfd8e0>, 9172101.927805774)]']
connector: <aiohttp.connector.TCPConnector object at 0x7ff531b45970>
And looking around a little more, I discovered that my code AND the example blinkapp.py
BOTH HAVE THE SAME FLAW:
When creating a new Auth()
, they do not pass in the same session
object. Therefore, Auth.__init__()
creates a second ClientSession
.
The fix to the example code blinkapp.py
on line 27 is to pass the same session
object to Auth()
:
blink.auth = Auth(await json_load(CREDFILE), session=session)
Oh boy - that was "easy" :) I also reviewed my blinksync.py
app - which was correct. Thanks for figuring it out!