我有一个Python 3.5
/ Django 1.10
的应用程序通过提供服务Apache
/ mod_wsgi
SSL上。 它被连接到Postgres 9.5.2
数据库(用psycopg2==2.6.2
)中,在一个服务器上运行AlwaysData
它工作正常,大部分的时间,但我有时我不理解错误。
(SSL error: called a function you should not call)
如果我把下面的数据库设置:错误似乎发生每次
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'host',
'PORT': '',
'OPTIONS': {
'sslmode': 'require',
},
}
}
这似乎在查询数据库发生。
# django/db/backends/utils.py line 64
return self.cursor.execute(sql, params)
当REST API(使用Django静止框架制造)由Angular2应用程序称为出现问题。
我已经激活了如下设置:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
为什么会发生? 如何解决在我的Django项目这个问题。
注意: 这个问题看起来类似,但所以不是非常有帮助,我不直接管理的OpenSSL层。
编辑:这里是完整的回溯
File "proj/env/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "proj/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)
File "proj/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "proj/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "proj/env/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "proj/env/lib/python3.5/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "proj/env/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
474. response = self.handle_exception(exc)
File "proj/env/lib/python3.5/site-packages/rest_framework/views.py" in handle_exception
434. self.raise_uncaught_exception(exc)
File "proj/env/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
471. response = handler(request, *args, **kwargs)
File "proj/apps/costs/apis.py" in get
296. data = self.get_spends_stats(cost_items, perimeter, start_date, end_date)
File "proj/apps/costs/apis.py" in get_spends_stats
306. for building in buildings:
File "proj/env/lib/python3.5/site-packages/django/db/models/query.py" in __iter__
256. self._fetch_all()
File "proj/env/lib/python3.5/site-packages/django/db/models/query.py" in _fetch_all
1087. self._result_cache = list(self.iterator())
File "proj/env/lib/python3.5/site-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql()
File "proj/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
835. cursor.execute(sql, params)
File "proj/env/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "proj/env/lib/python3.5/site-packages/django/db/utils.py" in __exit__
94. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "proj/env/lib/python3.5/site-packages/django/utils/six.py" in reraise
685. raise value.with_traceback(tb)
File "proj/env/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
Exception Type: OperationalError at /costs/api/benchmark/cost-center/3/38/2016-01/2017-12/
Exception Value: SSL error: called a function you should not call