官方错误是"类型'NoneType'的参数不可迭代";
做一些挖掘,我注意到mssql看到'PASSWORD'为None,即使它是在settings (os.environ.get('DBPW')
)
中定义的在python3 manage.py shell
中做os.environ.get('DBPW')
给我正确的密码,在shell中做settings.DATABASES['default']
也显示正确的密码,所以我知道这是mssql中的某种故障。
以下是我的设置:
DATABASES = {
'default': {
'ENGINE': 'mssql',
'NAME': 'tc_django_dev',
'USER': 'SA',
'PASSWORD': os.environ.get('DBPW'),
'HOST': 'localhost',
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
},
},
}
这是(python) mssql说它有:
conn_params
:
{'ATOMIC_REQUESTS': False,
'AUTOCOMMIT': True,
'CONN_MAX_AGE': 0,
'ENGINE': 'mssql',
'HOST': 'localhost',
'NAME': 'tc_django',
'OPTIONS': {'driver': 'ODBC Driver 17 for SQL Server'},
'PASSWORD': None,
'PORT': '',
'TEST': {'CHARSET': None,
'COLLATION': None,
'MIGRATE': True,
'MIRROR': None,
'NAME': None},
'TIME_ZONE': None,
'USER': 'SA'}
帮助。
完整回溯:
Aug 22 09:39:53 tclnx01 gunicorn[2634]: Internal Server Error: /accounts/login/
Aug 22 09:39:53 tclnx01 gunicorn[2634]: Traceback (most recent call last):
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
Aug 22 09:39:53 tclnx01 gunicorn[2634]: response = get_response(request)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
Aug 22 09:39:53 tclnx01 gunicorn[2634]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return self.dispatch(request, *args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return bound_method(*args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/views/decorators/debug.py", line 89, in sensitive_post_parameters_wrapper
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return view(request, *args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/allauth/account/views.py", line 138, in dispatch
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return super(LoginView, self).dispatch(request, *args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/allauth/account/views.py", line 78, in dispatch
Aug 22 09:39:53 tclnx01 gunicorn[2634]: response = super(RedirectAuthenticatedUserMixin,
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return handler(request, *args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/allauth/account/views.py", line 94, in get
Aug 22 09:39:53 tclnx01 gunicorn[2634]: response = super(AjaxCapableProcessFormViewMixin, self).get(
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/views/generic/edit.py", line 133, in get
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return self.render_to_response(self.get_context_data())
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/allauth/account/views.py", line 169, in get_context_data
Aug 22 09:39:53 tclnx01 gunicorn[2634]: site = get_current_site(self.request)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/contrib/sites/shortcuts.py", line 13, in get_current_site
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return Site.objects.get_current(request)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/contrib/sites/models.py", line 58, in get_current
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return self._get_site_by_id(site_id)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/contrib/sites/models.py", line 30, in _get_site_by_id
Aug 22 09:39:53 tclnx01 gunicorn[2634]: site = self.get(pk=site_id)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return getattr(self.get_queryset(), name)(*args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/models/query.py", line 425, in get
Aug 22 09:39:53 tclnx01 gunicorn[2634]: num = len(clone)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/models/query.py", line 269, in __len__
Aug 22 09:39:53 tclnx01 gunicorn[2634]: self._fetch_all()
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/models/query.py", line 1303, in _fetch_all
Aug 22 09:39:53 tclnx01 gunicorn[2634]: self._result_cache = list(self._iterable_class(self))
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/models/query.py", line 53, in __iter__
Aug 22 09:39:53 tclnx01 gunicorn[2634]: results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1143, in execute_sql
Aug 22 09:39:53 tclnx01 gunicorn[2634]: sql, params = self.as_sql()
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/compiler.py", line 188, in as_sql
Aug 22 09:39:53 tclnx01 gunicorn[2634]: supports_offset_clause = self.connection.sql_server_version >= 2012
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
Aug 22 09:39:53 tclnx01 gunicorn[2634]: res = instance.__dict__[self.name] = self.func(instance)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/base.py", line 414, in sql_server_version
Aug 22 09:39:53 tclnx01 gunicorn[2634]: with self.temporary_connection() as cursor:
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return next(self.gen)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/backends/base/base.py", line 603, in temporary_connection
Aug 22 09:39:53 tclnx01 gunicorn[2634]: with self.cursor() as cursor:
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return func(*args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return self._cursor()
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/base.py", line 230, in _cursor
Aug 22 09:39:53 tclnx01 gunicorn[2634]: conn = super()._cursor()
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
Aug 22 09:39:53 tclnx01 gunicorn[2634]: self.ensure_connection()
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return func(*args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
Aug 22 09:39:53 tclnx01 gunicorn[2634]: self.connect()
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return func(*args, **kwargs)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
Aug 22 09:39:53 tclnx01 gunicorn[2634]: self.connection = self.get_new_connection(conn_params)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/base.py", line 307, in get_new_connection
Aug 22 09:39:53 tclnx01 gunicorn[2634]: connstr = encode_connection_string(cstr_parts)
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/base.py", line 52, in encode_connection_string
Aug 22 09:39:53 tclnx01 gunicorn[2634]: return ';'.join(
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/base.py", line 53, in <genexpr>
Aug 22 09:39:53 tclnx01 gunicorn[2634]: '%s=%s' % (k, encode_value(v))
Aug 22 09:39:53 tclnx01 gunicorn[2634]: File "/home/webadmin/dev.taracares.com/dev/lib/python3.8/site-packages/mssql/base.py", line 62, in encode_value
Aug 22 09:39:53 tclnx01 gunicorn[2634]: if ';' in v or v.strip(' ').startswith('{'):
Aug 22 09:39:53 tclnx01 gunicorn[2634]: TypeError: argument of type 'NoneType' is not iterable
可以试试os吗?environ['DBPW']代替。get方法?