2017-09-06 15 views
1

내가 ldap.SCOPE_SUBTREE를 사용하는 경우 I는 다음과 같은 구성은 LDAP에 대해, 그것은 표시했다가 없습니다 :파이썬 3.4 장고 V-1.9 : - LDAP를 문제 모듈 오브젝트가 속성 SCOPE_SUBTREE

ldap3.SCOPE_SUBTREE, "(uid=%(user)s)") 
AttributeError: 'module' object has no attribute 'SCOPE_SUBTREE' 

내가 ldap3.SUBTREE를 사용하는 경우를 -

File "C:\Python34\lib\site-packages\django_auth_ldap-1.2.13-py3.4.eg\django_auth_ldap\config.py", line 65, in get_ldap 
ImportError: No module named 'ldap.filter' in 

[LDAP-Error.docx](https://github.com/cannatag/ldap3/files/1280858/LDAP-Error.docx) 

코드 : 나타나는 오류

#Specify User Profile Model if profile needs to be populated (Optional) 
#AUTH_PROFILE_MODULE = 'account.UserProfile' 

#Baseline configuration. 
AUTH_LDAP_SERVER_URI = "ldap://server ip" 

AUTH_LDAP_BIND_DN = "[email protected]" 
AUTH_LDAP_BIND_PASSWORD = "xxxxxxxxxx" 
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com", 
    ldap3.SUBTREE, "(uid=%(user)s)") 

#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com" 

# Set up the basic group parameters. 

#AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=users,dc=example", 
#  ldap3.SUBTREE,"(objectClass=posixGroup)" 

#) 
#LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson" 
#AUTH_LDAP_GROUP_TYPE = PosixGroupType() 
#group = PUN-GLOBALSUPPORT 
# Simple group restrictions 
#AUTH_LDAP_REQUIRE_GROUP = "cn=enabled,ou=django,ou=groups,dc=example,dc=com" 
#AUTH_LDAP_DENY_GROUP = "cn=disabled,ou=django,ou=groups,dc=example,dc=com" 

#Populate the Django user from the LDAP directory. 
AUTH_LDAP_USER_ATTR_MAP = { 
    "first_name": "givenName", 
    "last_name": "sn", 
    "email": "mail" 
} 

AUTH_LDAP_PROFILE_ATTR_MAP = { 
    "employee_number": "employeeNumber" 
} 

AUTH_LDAP_USER_FLAGS_BY_GROUP = { 
    "is_active": "cn=active,ou=groups,dc=PUN", 
    "is_staff": "cn=staff,ou=groups,dc=PUN", 
    "is_superuser": "cn=superuser,ou=groups,dc=PUN" 
} 

AUTH_LDAP_PROFILE_FLAGS_BY_GROUP = { 
    "is_awesome": ["cn=awesome,ou=groups,dc=PUN"] 
} 

#AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=PUN", 
# ldap.SCOPE_SUBTREE, "(cn=%(user)s)") 
# This is the default, but I like to be explicit. 
AUTH_LDAP_ALWAYS_UPDATE_USER = True 

# Use LDAP group membership to calculate group permissions. 
#AUTH_LDAP_FIND_GROUP_PERMS = True 

# Cache group memberships for an hour to minimize LDAP traffic 
AUTH_LDAP_CACHE_GROUPS = True 
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 


# Keep ModelBackend around for per-user permissions and maybe a local 
#Configuration for LDAP 
# superuser. 
AUTHENTICATION_BACKENDS = (
    'django_python3_ldap.auth.LDAPBackend', 
    'django_auth_ldap.backend.LDAPBackend', 
    'django.contrib.auth.backends.ModelBackend', 
) 

#Enable Logging method 1 
LOGGING = { 
    "version": 1, 
    "disable_existing_loggers": False, 
    "handlers": { 
     "console": { 
      "class": "logging.StreamHandler", 
     }, 
    }, 
    "loggers": { 
     "django_python3_ldap": { 
      "handlers": ["console"], 
      "level": "INFO", 
     }, 
    }, 
} 
##Enable Logging method 2. Enable debug for ldap server connection 
#logger = logging.getLogger('django_auth_ldap') 
#logger.addHandler(logging.StreamHandler()) 
#logger.setLevel(logging.DEBUG) 
+0

다운 그레이드 파이썬 버전 –

답변

0

은 저도 같은 문제를 겪고 있지만, 문제를 해결 할 수 있었다 아주.

python2 용 ldap 패키지의 __init__.py을 python3 용 패키지에 복사해야합니다.

python2의 ldap 패키지 위치를 찾으십시오. 을 예로 들어 보겠습니다. 의도 python3에 대해 동일한 패키지 /site-packages/python3/ldap

이 작업을 수행 할 것입니다 가정 해 봅시다 :

cp /site-packages/python2/ldap/__init__.py /site-packages/python3/ldap

+0

예 ...이 일 및 2.7. 나는 똑같이했다. 그것은 효과가 있었다. 감사! –

+0

@SahilSahay 제 대답에 답하십시오. – SmallChess