noirello / bonsai

Simple Python 3 module for LDAP, using libldap2 and winldap C libraries.
MIT License
116 stars 32 forks source link

NotImplementedError with is_async=True #63

Closed max-dw-i closed 1 year ago

max-dw-i commented 2 years ago

Code snippet:

async def do():
    cli = bonsai.LDAPClient("ldap://localhost")
    async with cli.connect(is_async=True) as conn:
        results = await conn.search("ou=nerdherd,dc=bonsai,dc=test", 1)
        for res in results:
            print(res['givenName'][0])
        search = await conn.search("cn=chuck,ou=nerdherd,dc=bonsai,dc=test", 0)
        entry = search[0]
        entry['mail'] = "chuck@nerdherd.com"
        await entry.modify()

asyncio.run(do())

Traceback:

python ldap.py
Traceback (most recent call last):
  File "C:\Users\user\Documents\Projects\ldap\ldap.py", line 78, in <module>
    asyncio.run(do())
  File "C:\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
    return future.result()
  File "C:\Users\mshpak\Documents\Projects\telegram-bot-with-authentication\ldap.py", line 69, in do
    async with cli.connect(is_async=True) as conn:
  File "C:\Users\user\Documents\Projects\venv\ldap\lib\site-packages\bonsai\asyncio\aioconnection.py", line 25, in aenter
    return await self.__open_coro
  File "C:\Users\user\Documents\Projects\venv\ldap\lib\site-packages\bonsai\asyncio\aioconnection.py", line 51, in _poll
    self._loop.add_reader(self.fileno(), self._ready, msg_id, fut)
  File "C:\Python310\lib\asyncio\events.py", line 518, in add_reader
    raise NotImplementedError
NotImplementedError

Win 10, Python 3.10.0 Linux (tested on Debian) is ok.

noirello commented 2 years ago

The default event loop implementation has changed on Windows since 3.8. See note in the docs.

max-dw-i commented 2 years ago

Thanks, I did not see it. Maybe It makes sense to add a link to this part of the documentation? Some people could try the example on Linux and think (naively, like me) that it should work on Win also. P.S. It's not a good practice to go open a new issue without having a look at the whole docs. Sorry, my bad :)

noirello commented 2 years ago

No worries, and to be honest, when I read your issue, first I went to the Advanced part of the docs, then I realised I put the note to the API part. So yes, it completely makes sense. I keep this issue open as reminder to update the docs about this.

noirello commented 1 year ago

The docs are updated.