2017-09-06 5 views
1

私はLDAPのために以下の構成を持っているを持っていない私はldap.SCOPE_SUBTREEを使用している場合、それは示していますのPython-3.4 Djangoの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

ダウングレードPythonのバージョン –

答えて

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

関連する問題