ldap import problem

307 views
Skip to first unread message

Johann Spies

unread,
Aug 20, 2015, 8:20:55 AM8/20/15
to web...@googlegroups.com
Why does this happen?  The import process seems to try and import the ldap module from the modules directory and not from gluon/contrib/login_methods.

File "/home/js/web2py/applications/wos_2015_3/models/db.py", line 11, in <module>
from gluon.contrib.login_methods.ldap_auth import ldap_auth
File "/home/js/web2py/gluon/custom_import.py", line 108, in custom_importer
return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
File "/home/js/web2py/gluon/contrib/login_methods/ldap_auth.py", line 14, in <module>
raise e
ImportError: Cannot import module 'applications.wos_2015_3.modules.ldap'

Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

Richard Vézina

unread,
Aug 20, 2015, 10:00:45 AM8/20/15
to web2py-users
Johann which version of web2py?

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimo Di Pierro

unread,
Aug 20, 2015, 3:04:53 PM8/20/15
to web2py-users
web2py always trying the app/modules folder before anywhere else. That is how it allows an app to bring along the modules it requires and not conflict with those pre-installed.

That said. The error you see does not mean it does not also look somewhere else.
 Do you actually have an app/modules/ldap? from the error it looks like you have one and it does not work. You should perhaps remove it.

Johann Spies

unread,
Aug 24, 2015, 3:13:25 AM8/24/15
to web...@googlegroups.com
Thanks Richard and Massimo for your replies.

Version 2.12.3-stable+timestamp.2015.08.18.19.14.07


Massimo, there is nothing in modules - only __init__.py

This is a new app. 

Regards
Johann

Massimo Di Pierro

unread,
Aug 24, 2015, 10:20:27 AM8/24/15
to web2py-users
So the problem is that it cannot import ldal. Do you know it works from the normal python shell?

>>> import ldap

Does it work from the web2py shell?

Johann Spies

unread,
Aug 25, 2015, 1:56:41 AM8/25/15
to web...@googlegroups.com
On 24 August 2015 at 16:20, Massimo Di Pierro <massimo....@gmail.com> wrote:

So the problem is that it cannot import ldal. Do you know it works from the normal python shell?

>>> import ldap

Does it work from the web2py shell?


No, I cannot import ldap. I also tried it from another app (welcome) this time:


In [1]: import ldap
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/js/web2py/applications/welcome/models/menu.py in <module>()
----> 1 import ldap

/home/js/web2py/gluon/custom_import.pyc in custom_importer(name, globals, locals, fromlist, level)
     87                             result = result or sys.modules[modules_prefix+'.'+itemname]
     88                         except KeyError, e:
---> 89                             raise ImportError, 'Cannot import module %s' % str(e)
     90                         modules_prefix += "." + itemname
     91                     return result

ImportError: Cannot import module 'applications.welcome.modules.ldap'

and the same with ldap_auth:

import ldap_auth
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/js/web2py/applications/welcome/models/menu.py in <module>()
----> 1 import ldap_auth

/home/js/web2py/gluon/custom_import.pyc in custom_importer(name, globals, locals, fromlist, level)
     87                             result = result or sys.modules[modules_prefix+'.'+itemname]
     88                         except KeyError, e:
---> 89                             raise ImportError, 'Cannot import module %s' % str(e)
     90                         modules_prefix += "." + itemname
     91                     return result

ImportError: Cannot import module 'applications.welcome.modules.ldap_auth'



Regards
Johann

Massimo Di Pierro

unread,
Aug 26, 2015, 11:58:35 AM8/26/15
to web2py-users
I understand that but that is not the problem. 

When you say import ldap, web2py tries to import it from various location. When it fails to import from all locations, it reports the error you see and the error include the path to the first location it tried. That does not mean that it did not try the other locations.

So, please try the regular python shell (not the web2py shell) and type there

import ldap

Massimo

Johann Spies

unread,
Aug 27, 2015, 2:45:08 AM8/27/15
to web...@googlegroups.com
Thanks Massimo.  After installing python-ldap the problem was solved.  I did not realise that the package in gluon/contrib was dependent on external stuff.

Reply all
Reply to author
Forward
0 new messages