我有Django服务,最近我在其中添加了OneLogin SSO。一切在本地计算机上都可以正常工作,但是在服务器上,登录视图会在每个请求上引发此ImportError。
ImportError: Interpreter change detected - this module can only be loaded into one interpreter per process.
完整的堆栈跟踪为
Traceback (most recent call last):
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 172, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/urls/resolvers.py", line 267, in resolve
for pattern in self.url_patterns:
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/django/urls/resolvers.py", line 303, in urlconf_module
return import_module(self.urlconf_name)
File "/.virtualenvs/dj/lib64/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "./bwell_clientportal/urls.py", line 23, in <module>
from bwell_clientportal.apps.onelogin_sso import views as onelogin_views
File "./bwell_clientportal/apps/onelogin_sso/views.py", line 9, in <module>
from onelogin.saml2.auth import OneLogin_Saml2_Auth
File "/.virtualenvs/dj/local/lib/python3.5/site-packages/onelogin/saml2/auth.py", line 14, in <module>
import xmlsec
ImportError: Interpreter change detected - this module can only be loaded into one interpreter per process.
我正在将python 3.5.1与Django 1.11和python3-saml
一起用于SSO。
该机器在AWS上使用Amazon AMI。
答案 0 :(得分:1)
原来,我们在线程中使用uwsgi,每个线程都在创建自己的解释器。
我们要做的就是更新ini file
以使用单个解释器。
single-interpreter=True