我正在尝试实施LDAP。我使用以下作为指导。 https://code.tutsplus.com/tutorials/flask-authentication-with-ldap--cms-23101
根据以下教程的评论,我使用了
current_user.is_authenticated:而不是 current_user.is_authenticated():
应用程序已启动,但是,当我尝试使用登录LDAP时,我遇到以下错误。
Traceback (most recent call last):
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "home/user//anaconda/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "home/user/Desktop/flask_app/my_app/auth/views.py", line 41, in login
User.try_login(username, password)
File "home/user/Desktop/flask_app/my_app/auth/models.py", line 22, in try_login
conn = get_ldap_connection()
File "home/user/Desktop/flask_app/my_app/auth/models.py", line 9, in get_ldap_connection
conn = ldap.initialize(app.config['LDAP_PROVIDER_URL'])
File "home/user/anaconda/lib/python2.7/site-packages/ldap/functions.py", line 94, in initialize
return LDAPObject(uri,trace_level,trace_file,trace_stack_limit)
File "home/user/anaconda/lib/python2.7/site-packages/ldap/ldapobject.py", line 77, in __init__
self._l = ldap.functions._ldap_function_call(ldap._ldap_module_lock,_ldap.initialize,uri)
File "home/user/anaconda/lib/python2.7/site-packages/ldap/functions.py", line 66, in _ldap_function_call
result = func(*args,**kwargs)
LDAPError: (2, 'No such file or directory')
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "home/user/anaconda/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "home/user/Desktop/flask_app/my_app/auth/views.py", line 41, in login
User.try_login(username, password)
File "home/user/Desktop/flask_app/my_app/auth/models.py", line 22, in try_login
conn = get_ldap_connection()
File "home/user/Desktop/flask_app/my_app/auth/models.py", line 9, in get_ldap_connection
conn = ldap.initialize(app.config['LDAP_PROVIDER_URL'])
File "home/user/anaconda/lib/python2.7/site-packages/ldap/functions.py", line 94, in initialize
return LDAPObject(uri,trace_level,trace_file,trace_stack_limit)
File "home/user/anaconda/lib/python2.7/site-packages/ldap/ldapobject.py", line 77, in __init__
self._l = ldap.functions._ldap_function_call(ldap._ldap_module_lock,_ldap.initialize,uri)
File "home/user/anaconda/lib/python2.7/site-packages/ldap/functions.py", line 66, in _ldap_function_call
result = func(*args,**kwargs)
LDAPError: (0, 'Error')
我的LDAP提供程序URL我已经选择使用两个选项
app.config['LDAP_PROVIDER_URL'] = 'xxx.xxxx.net/CN=xxx,DC=xxx,DC=xxx,DC=net'
和
app.config['LDAP_PROVIDER_URL'] = 'xxx.xxxx.net
但是,我无法得到答案。我该怎么办?
答案 0 :(得分:1)
你还没有提到的一些事情,我必须检查:
您是否在PROVIDER_URL中添加了端口等等?
您是否添加了完整格式:ldap://ldap.testathon.net:389 /?
最后,确认LDAP实际上正在使用ldapsearch,如下所示:
dotnet new
如果所有这些都没问题,您需要发布“flask_app / my_app / init .py”。
答案 1 :(得分:1)
我遇到了类似的问题。我设法解决了这个问题:
我改变了
connect = ldap.initialize("x.x.x.x")
对此
connect = ldap.initialize("ldap://x.x.x.x")