noirello / bonsai

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

bonsai.errors.LDAPError: Operations error #34

Closed reach4bawer closed 4 years ago

reach4bawer commented 4 years ago

Hi, I am running into the following error with the code.

I am working with a virtual active directory connection,(Ldap3 over SSL)

Code:

compiled_search_filter = '(&(objectCategory=person)(objectClass=user)(memberOf:1.2.840.113556.1.4.1941:=CN=ADgroup,OU=test,OU=sys,DC=a,DC=b,DC=com))'
async with client.connect(is_async=True) as conn:
        res = []
        result = await conn.paged_search(base="", scope=2, filter_exp=compiled_search_filter,
                                         attrlist=['employeeID', 'sAMAccountName','objectClass','DistinguishedName'],
                                         timeout=10,attrsonly=True,page_size=1000)
        async for r in result:
            res.append(r)

Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('/Users/bawer/Documents/Automation Projects/Test/Bonsai_AD_Domains.py', wdir='/Users/bawer/Documents/Automation Projects/Test') File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/bawer/Documents/Automation Projects/Test/Bonsai_AD_Domains.py", line 87, in res = loop.run_until_complete(get_members(group_name)) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete return future.result() File "/Users/bawer/Documents/Automation Projects/Test/Bonsai_AD_Domains.py", line 70, in get_members attrlist=['employeeID', 'sAMAccountName','objectClass','DistinguishedName'],timeout=10,attrsonly=True,page_size=1000) File "/usr/local/lib/python3.7/site-packages/bonsai-1.2.0-py3.7-macosx-10.14-x86_64.egg/bonsai/asyncio/aioconnection.py", line 64, in _poll debug.txt

raise exc

File "/usr/local/lib/python3.7/site-packages/bonsai-1.2.0-py3.7-macosx-10.14-x86_64.egg/bonsai/asyncio/aioconnection.py", line 59, in _poll return await asyncio.wait_for(fut, timeout) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/local/lib/python3.7/site-packages/bonsai-1.2.0-py3.7-macosx-10.14-x86_64.egg/bonsai/asyncio/aioconnection.py", line 45, in _ready res = super().get_result(msg_id) bonsai.errors.LDAPError: Operations error. (0x0001 [1])

The query seems to work with JXplorer. It seems the connection might be timing out.

Debug logs attached

With is_async=False I get the following error -

File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete return future.result() File "/Users/bawer/Documents/Automation Projects/Test/Bonsai_AD_Domains.py", line 23, in find_dn async with client.connect(is_async=False) as conn: AttributeError: aexit

noirello commented 4 years ago

Hi, did you try the same search with synchronous connection? Did it produce the same result?

reach4bawer commented 4 years ago

Hi, did you try the same search with synchronous connection? Did it produce the same result?

Update the question with is_async=False error as well.

reach4bawer commented 4 years ago

The error was for Bonsai version 1.2.0 For version 1.1.0 python crashes and I get the error when running via pycharm-

    __TEXT                 0000000104ef2000-0000000104ef4000 [    8K] r-x/rwx SM=COW  /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libssl.1.0.0.dylib              0x000000010ac58043 ssl3_ctx_callback_ctrl + 162
1   libldap-2.4.2.10.10.dylib       0x000000010ac21bba tlso_ctx_init + 779
2   libldap-2.4.2.10.10.dylib       0x000000010ac1ff75 ldap_int_tls_init_ctx + 180
3   libldap-2.4.2.10.10.dylib       0x000000010ac175ff ldap_set_option + 1075
4   _bonsai.cpython-37m-darwin.so   0x000000010abea7b5 LDAPConnectIter_Next + 869
5   _bonsai.cpython-37m-darwin.so   0x000000010abeb76b LDAPConnection_Result + 235
6   _bonsai.cpython-37m-darwin.so   0x000000010abed38e ldapconnection_result + 286
7   org.python.python               0x0000000104f11560 _PyMethodDef_RawFastCallKeywords + 544
8   org.python.python               0x0000000104f10ab2 _PyCFunction_FastCallKeywords + 44
9   org.python.python               0x0000000104fa5e82 call_function + 636
10  org.python.python               0x0000000104f9ec70 _PyEval_EvalFrameDefault + 6421
11  org.python.python               0x0000000104fa67a6 _PyEval_EvalCodeWithName + 1870
12  org.python.python               0x0000000104f106e5 _PyFunction_FastCallDict + 441
13  org.python.python               0x0000000104f11829 _PyObject_Call_Prepend + 150
14  org.python.python               0x0000000104f10918 _PyObject_FastCallKeywords + 358
15  org.python.python               0x0000000104fc7ba7 context_run + 62
16  org.python.python               0x0000000104f11052 _PyMethodDef_RawFastCallDict + 269
17  org.python.python               0x0000000104f10765 _PyCFunction_FastCallDict + 44
18  org.python.python               0x0000000104f9f022 _PyEval_EvalFrameDefault + 7367
19  org.python.python               0x0000000104f10e8c function_code_fastcall + 112
20  org.python.python               0x0000000104fa5ef7 call_function + 753
21  org.python.python               0x0000000104f9ec57 _PyEval_EvalFrameDefault + 6396
22  org.python.python               0x0000000104f10e8c function_code_fastcall + 112
23  org.python.python               0x0000000104fa5ef7 call_function + 753
24  org.python.python               0x0000000104f9ec57 _PyEval_EvalFrameDefault + 6396
25  org.python.python               0x0000000104f10e8c function_code_fastcall + 112
26  org.python.python               0x0000000104fa5ef7 call_function + 753
27  org.python.python               0x0000000104f9ec57 _PyEval_EvalFrameDefault + 6396
28  org.python.python               0x0000000104f10e8c function_code_fastcall + 112
29  org.python.python               0x0000000104fa5ef7 call_function + 753
30  org.python.python               0x0000000104f9ec57 _PyEval_EvalFrameDefault + 6396
31  org.python.python               0x0000000104fa67a6 _PyEval_EvalCodeWithName + 1870
32  org.python.python               0x0000000104f9d2b8 PyEval_EvalCode + 51
33  org.python.python               0x0000000104fcb94b run_mod + 54
34  org.python.python               0x0000000104fca975 PyRun_FileExFlags + 163
35  org.python.python               0x0000000104fca01b PyRun_SimpleFileExFlags + 263
36  org.python.python               0x0000000104fe289e pymain_main + 5389
37  org.python.python               0x0000000104fe2f80 _Py_UnixMain + 56
38  libdyld.dylib                   0x00007fff7b9033d5 start + 1

Thread 1:
0   libsystem_kernel.dylib          0x00007fff7ba3b86a __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00007fff7bafa56e _pthread_cond_wait + 722
2   libopenblasp-r0.3.7.dev.dylib   0x00000001060f6c0b blas_thread_server + 619
3   libsystem_pthread.dylib         0x00007fff7baf72eb _pthread_body + 126
4   libsystem_pthread.dylib         0x00007fff7bafa249 _pthread_start + 66
5   libsystem_pthread.dylib         0x00007fff7baf640d thread_start + 13

Thread 2:
0   libsystem_kernel.dylib          0x00007fff7ba3b86a __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00007fff7bafa56e _pthread_cond_wait + 722
2   libopenblasp-r0.3.7.dev.dylib   0x00000001060f6c0b blas_thread_server + 619
3   libsystem_pthread.dylib         0x00007fff7baf72eb _pthread_body + 126
4   libsystem_pthread.dylib         0x00007fff7bafa249 _pthread_start + 66
5   libsystem_pthread.dylib         0x00007fff7baf640d thread_start + 13

Thread 3:
0   libsystem_kernel.dylib          0x00007fff7ba3b86a __psynch_cvwait + 10
1   libsystem_pthread.dylib         0x00007fff7bafa56e _pthread_cond_wait + 722
2   libopenblasp-r0.3.7.dev.dylib   0x00000001060f6c0b blas_thread_server + 619
3   libsystem_pthread.dylib         0x00007fff7baf72eb _pthread_body + 126
4   libsystem_pthread.dylib         0x00007fff7bafa249 _pthread_start + 66
5   libsystem_pthread.dylib         0x00007fff7baf640d thread_start + 13

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x00007fc6c7e96ef0  rcx: 0x000000010ac57fa1  rdx: 0x000000010ac228bf
  rdi: 0x0000000000000040  rsi: 0x0000000000000005  rbp: 0x00007ffeead0c010  rsp: 0x00007ffeead0c010
   r8: 0x000000000000001a   r9: 0x0000000000000000  r10: 0x000000000000001b  r11: 0x000000000000001b
  r12: 0x0000000000000000  r13: 0x00007fc6ca5058e0  r14: 0x00007fc6cb99e000  r15: 0x00007ffeead0c068
  rip: 0x000000010ac58043  rfl: 0x0000000000010202  cr2: 0x0000000000000040

Logical CPU:     4
Error Code:      0x00000006
Trap Number:     14

On running with Terminal I get -

[1] 25879 segmentation fault

On further checking. I updated my python version to -

Python 3.7.4 (default, Sep  7 2019, 18:27:02)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin

On pulling the history of python from brew I saw these. I suspect that the never version of python isn't compatible with bonsai 1.1.0 and bonsai 1.2.0 is slightly more compatible(atleast python does not crash)

commit 1c2239bfdfc868124c6505158889ec08d5dce741
Author: BrewTestBot <homebrew-test-bot@lists.sfconservancy.org>
Date:   Mon Sep 9 05:15:11 2019 +0000

    **python: update 3.7.4_1 bottle.**

commit 290e56ad8e46832288ea679fc0201a8e8bb50d30
Author: FX Coudert <fxcoudert@gmail.com>
Date:   Wed Sep 4 17:03:04 2019 +0200

    **python: move to OpenSSL 1.1**

commit 48aba7218e7506ca6d46c9c058c67d752072e89a
Author: BrewTestBot <homebrew-test-bot@lists.sfconservancy.org>
Date:   Tue Jul 9 23:23:43 2019 +0000

    python: update 3.7.4 bottle.

commit e444ff2889d6a61e7cca07d1d1a5428e3a33464e
Author: Alexander Bayandin <a.bayandin@gmail.com>
Date:   Tue Jul 9 11:14:34 2019 +0100

    python 3.7.4
noirello commented 4 years ago

Hi, did you try the same search with synchronous connection? Did it produce the same result?

Update the question with is_async=False error as well.

You also need to remove await and async keywords to be completely synchronous.

noirello commented 4 years ago

python: move to OpenSSL 1.1

That could be the culprit for the crash, but it's just a guess.

reach4bawer commented 4 years ago

python: move to OpenSSL 1.1

That could be the culprit for the crash, but it's just a guess.

That indeed was the culprit. Had to move to a previous version of python and reinstall OpenSSL.