2017-04-10 43 views
5

我想在macOS Sierra上設置python-ldap。 當我嘗試使用模塊(它在我在CentOS上運行的實時環境中工作) 我得到了下面的錯誤,它在搜索時看起來與在macOS上安裝OpenLDAP或python-ldap有關,但是我還沒有找到解釋如何解決它的文章。Python ldap macOS - ValueError:選項錯誤

我迄今通過自制尚未固定的問題安裝的OpenLDAP:

錯誤:

Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 42, in inner 
    response = get_response(request) 
    File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response 
    response = self._get_response(request) 
    File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response 
    response = self.process_exception_by_middleware(e, request) 
    File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response 
    response = wrapped_callback(request, *callback_args, **callback_kwargs) 
    File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/views.py", line 47, in inner 
    return func(*args, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper 
    return view(request, *args, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view 
    response = view_func(request, *args, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func 
    response = view_func(request, *args, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/views.py", line 81, in login 
    if form.is_valid(): 
    File "/usr/local/lib/python2.7/site-packages/django/forms/forms.py", line 169, in is_valid 
    return self.is_bound and not self.errors 
    File "/usr/local/lib/python2.7/site-packages/django/forms/forms.py", line 161, in errors 
    self.full_clean() 
    File "/usr/local/lib/python2.7/site-packages/django/forms/forms.py", line 371, in full_clean 
    self._clean_form() 
    File "/usr/local/lib/python2.7/site-packages/django/forms/forms.py", line 398, in _clean_form 
    cleaned_data = self.clean() 
    File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 191, in clean 
    self.user_cache = authenticate(username=username, password=password) 
    File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 74, in authenticate 
    user = backend.authenticate(**credentials) 
    File "/itapp/itapp/backend.py", line 39, in authenticate 
    ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,settings.AD_CERT_FILE) 
    File "/usr/local/lib/python2.7/site-packages/ldap/functions.py", line 135, in set_option 
    return _ldap_function_call(None,_ldap.set_option,option,invalue) 
    File "/usr/local/lib/python2.7/site-packages/ldap/functions.py", line 66, in _ldap_function_call 
    result = func(*args,**kwargs) 
ValueError: option error 

我已經通過釀造安裝OpenLDAP的具體根據下面

alexs-mbp:~ alex$ brew install openldap 
Warning: openldap is a keg-only and another version is linked to opt. 
Use `brew install --force` if you want to install this version 
alexs-mbp:~ alex$ brew install openldap --force 
Warning: openldap-2.4.44 already installed, it's just not linked. 

和我已經用pip安裝了python-ldap

alexs-mbp:~ alex$ sudo pip install python-ldap 
The directory '/Users/alex/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 
The directory '/Users/alex/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 
Requirement already satisfied: python-ldap in /usr/local/lib/python2.7/site-packages 
Requirement already satisfied: setuptools in /usr/local/lib/python2.7/site-packages (from python-ldap 
+0

看起來像是可能是openldap的自制構建問題 - 請參閱http://thread.gmane.org/gmane.comp.python.ldap/1660 –

+0

https ://sourceforge.net/p/python-ldap/bugs/65/看起來是根據那個固定的 – AlexW

+0

固定爲他們的具體環境。不過,您可能需要考慮解決方法。 –

回答

3

我的解決方案是,我需要包括基於BREW的OpenLDAP的庫做pip install python-ldap

你需要的信息可以發現,當通過做brew info openldap,它說是這樣的:

For compilers to find this software you may need to set: 
    LDFLAGS: -L/usr/local/brew/opt/openldap/lib 
    CPPFLAGS: -I/usr/local/brew/opt/openldap/include 

我OpenLDAP的安裝是在/usr/local/brew/opt/openldap/所以這需要像這樣的命令:

LDFLAGS="-L/usr/local/brew/opt/openldap/lib" CPPFLAGS="-I/usr/local/brew/opt/openldap/include" pip install python-ldap 

嘗試卸載蟒蛇,LDAP(pip uninstall python-ldap),然後運行brew info openldap和使用您的具體路徑,OpenLDAP的lib和include目錄在上面的命令

注:我也有一個問題,我的鏗鏘編譯器不找到MacOS SDK sasl.h,但我不知道這是不是我。這是通過將--global-option=build_ext --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl"添加到上述命令行來解決的

+0

應該說,確保你做一個'pip卸載python-ldap'首先讓它在你執行'install'時重新編譯 - 虐待編輯答案 – spacepickle

+0

這工作!我也必須做全球選擇 – AlexW

2

我安裝在Mac OS塞拉利昂10.12.4使用MacPorts與Python-LDAP(版本2.3.10_3):

sudo port install py27-ldap 

這也拉開OpenLDAP的依賴(2.4.44_2版)。

我可以執行的代碼:

import ldap 
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,'cacert-2017-01-18.pem') 

沒有錯誤(從https://curl.haxx.se/ca/cacert-2017-01-18.pem CA證書文件)

步驟,你遵循以下哪項安裝OpenLDAP和蟒蛇,LDAP

編輯:

我想我找到something relevant,你可以試試上面的測試代碼與我聯繫的證書文件?

我懷疑許可/ .pem格式的錯誤

+0

我已經添加我的安裝方法的問題,謝謝 – AlexW

+0

我下載了該文件,然後cd到該目錄並從該目錄運行python,然後上面的代碼,得到相同的ValueError: – AlexW