TypeError: initialize () получил неожиданный аргумент ключевого слова 'bytes_mode' - PullRequest
0 голосов
/ 19 декабря 2018

Я недавно настроил django на apache, используя modwsgi.Он отлично работает, когда я отключаю аутентификацию в моем приложении.Но, это дает ниже ошибку, когда аутентификация включена.Я использую модуль django_auth_ldap для аутентификации.

Я использую Python 2.7, Django 1.11.15 и версию apache 2.4.6.

Журналы ошибок: -

    [Wed Dec 19 14:23:30.351155 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] python version
    [Wed Dec 19 14:23:30.351187 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] 2.7.5 (default, Oct 30 2018, 23:45:53)
    [Wed Dec 19 14:23:30.351260 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
    [Wed Dec 19 14:23:30.351290 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] django version
    [Wed Dec 19 14:23:30.351390 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] 1.11.15
    [Wed Dec 19 14:23:30.359768 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] Internal Server Error: /login/
    [Wed Dec 19 14:23:30.359839 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] Traceback (most recent call last):
    [Wed Dec 19 14:23:30.359855 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    [Wed Dec 19 14:23:30.359864 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     response = get_response(request)
    [Wed Dec 19 14:23:30.359874 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    [Wed Dec 19 14:23:30.359883 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     response = self.process_exception_by_middleware(e, request)
    [Wed Dec 19 14:23:30.359949 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    [Wed Dec 19 14:23:30.359961 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    [Wed Dec 19 14:23:30.359979 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    [Wed Dec 19 14:23:30.360103 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     return view_func(*args, **kwargs)
    [Wed Dec 19 14:23:30.360139 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    [Wed Dec 19 14:23:30.360150 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     return view_func(*args, **kwargs)
    [Wed Dec 19 14:23:30.360163 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    [Wed Dec 19 14:23:30.360173 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     return self.dispatch(request, *args, **kwargs)
    [Wed Dec 19 14:23:30.360185 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 483, in dispatch
    [Wed Dec 19 14:23:30.360195 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     response = self.handle_exception(exc)
    [Wed Dec 19 14:23:30.360204 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 443, in handle_exception
    [Wed Dec 19 14:23:30.360213 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self.raise_uncaught_exception(exc)
    [Wed Dec 19 14:23:30.360221 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 480, in dispatch
    [Wed Dec 19 14:23:30.360234 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     response = handler(request, *args, **kwargs)
    [Wed Dec 19 14:23:30.360265 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/rest_framework/decorators.py", line 53, in handler
    [Wed Dec 19 14:23:30.360304 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     return func(*args, **kwargs)
    [Wed Dec 19 14:23:30.360318 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/home/testuser/django/test_project/endpoints/views.py", line 294, in user_login
    [Wed Dec 19 14:23:30.360328 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     user = django.contrib.auth.authenticate(username=username, password=password)
    [Wed Dec 19 14:23:30.360340 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 70, in authenticate
    [Wed Dec 19 14:23:30.360350 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     user = _authenticate_with_backend(backend, backend_path, request, credentials)
    [Wed Dec 19 14:23:30.360363 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 116, in _authenticate_with_backend
    [Wed Dec 19 14:23:30.360373 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     return backend.authenticate(*args, **credentials)
    [Wed Dec 19 14:23:30.360385 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 149, in authenticate
    [Wed Dec 19 14:23:30.360394 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     user = self.authenticate_ldap_user(ldap_user, password)
    [Wed Dec 19 14:23:30.360403 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 209, in authenticate_ldap_user
    [Wed Dec 19 14:23:30.360415 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     return ldap_user.authenticate(password)
    [Wed Dec 19 14:23:30.360487 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 366, in authenticate
    [Wed Dec 19 14:23:30.360507 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self._authenticate_user_dn(password)
    [Wed Dec 19 14:23:30.360551 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 489, in _authenticate_user_dn
    [Wed Dec 19 14:23:30.360575 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     if self.dn is None:
    [Wed Dec 19 14:23:30.360585 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 454, in dn
    [Wed Dec 19 14:23:30.360599 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self._load_user_dn()
    [Wed Dec 19 14:23:30.360634 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 527, in _load_user_dn
    [Wed Dec 19 14:23:30.360666 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self._user_dn = self._search_for_user_dn()
    [Wed Dec 19 14:23:30.360676 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 549, in _search_for_user_dn
    [Wed Dec 19 14:23:30.360690 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     results = search.execute(self.connection, {'user': self._username})
    [Wed Dec 19 14:23:30.360743 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 476, in connection
    [Wed Dec 19 14:23:30.360794 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self._bind()
    [Wed Dec 19 14:23:30.360828 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 804, in _bind
    [Wed Dec 19 14:23:30.360838 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     sticky=True)
    [Wed Dec 19 14:23:30.360851 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 815, in _bind_as
    [Wed Dec 19 14:23:30.360901 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self._get_connection().simple_bind_s(force_text(bind_dn),
    [Wed Dec 19 14:23:30.360969 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]   File "/usr/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 829, in _get_connection
    [Wed Dec 19 14:23:30.361067 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774]     self._connection = self.backend.ldap.initialize(uri, bytes_mode=False)
    [Wed Dec 19 14:23:30.361175 2018] [wsgi:error] [pid 17609] [client 100.81.144.164:55774] TypeError: initialize() got an unexpected keyword argument 'bytes_mode'

Пожалуйста, помогите.

Редактировать: -

wsgi.py

import site, sys
import os
site.addsitedir('/usr/local/lib/python2.7/site-packages') 
from django.core.wsgi import get_wsgi_application

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR) 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
application = get_wsgi_application()

httpd.conf :-

LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
LoadModule headers_module /usr/lib64/httpd/modules/mod_headers.so

WSGIScriptAlias / /home/testuser/django/test_project/test_project/wsgi.py
WSGIPythonPath /home/testuser/django/test_project

<Directory /home/testuser/django/test_project/test_project>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
...