twtrubiks / docker-tutorial

Docker 基本教學 - 從無到有 Docker-Beginners-Guide 教你用 Docker 建立 Django + PostgreSQL 📝
MIT License
1.6k stars 296 forks source link

AssertionError at /api-auth/login/ database connection isn't set to UTC #12

Closed cgl0408 closed 3 years ago

cgl0408 commented 3 years ago

您好,我執行您的教學至連上網站登入密碼時那邊出錯 問題解決方式 目前參考網路上主要有兩種做法 一種是將psycopg2 downgrade至2.8.6 因此我直接在更改requirements.txt為 image 另一種則是在setting裡的 USE_TZ = True更改为USE_TZ = False image

兩種改動都是更改後重新compose up不過錯誤一樣出現 請問此問題如何解決

twtrubiks commented 3 years ago

錯誤訊息是甚麼呢?

cgl0408 commented 3 years ago

web_1 | Traceback (most recent call last): web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner web_1 | response = get_response(request) web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response web_1 | response = self.process_exception_by_middleware(e, request) web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view web_1 | return self.dispatch(request, *args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 67, in _wrapper web_1 | return bound_func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper web_1 | return view(request, *args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 63, in bound_func web_1 | return func.__get__(self, type(self))(*args2, **kwargs2) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 67, in _wrapper web_1 | return bound_func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 149, in _wrapped_view web_1 | response = view_func(request, *args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 63, in bound_func web_1 | return func.__get__(self, type(self))(*args2, **kwargs2) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 67, in _wrapper web_1 | return bound_func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func web_1 | response = view_func(request, *args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 63, in bound_func web_1 | return func.__get__(self, type(self))(*args2, **kwargs2) web_1 | File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/views.py", line 90, in dispatch web_1 | return super(LoginView, self).dispatch(request, *args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch web_1 | return handler(request, *args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/edit.py", line 182, in post web_1 | if form.is_valid(): web_1 | File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", line 183, in is_valid web_1 | return self.is_bound and not self.errors web_1 | File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", line 175, in errors web_1 | self.full_clean() web_1 | File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", line 385, in full_clean web_1 | self._clean_form() web_1 | File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", line 412, in _clean_form web_1 | cleaned_data = self.clean() web_1 | File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 202, in clean web_1 | self.user_cache = authenticate(self.request, username=username, password=password) web_1 | File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 70, in authenticate web_1 | user = _authenticate_with_backend(backend, backend_path, request, credentials) web_1 | File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 116, in _authenticate_with_backend web_1 | return backend.authenticate(*args, **credentials) web_1 | File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/backends.py", line 18, in authenticate web_1 | user = UserModel._default_manager.get_by_natural_key(username) web_1 | File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 48, in get_by_natural_key web_1 | return self.get(**{self.model.USERNAME_FIELD: username}) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method web_1 | return getattr(self.get_queryset(), name)(*args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 374, in get web_1 | num = len(clone) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 232, in __len__ web_1 | self._fetch_all() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1121, in _fetch_all web_1 | self._result_cache = list(self._iterable_class(self)) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 62, in __iter__ web_1 | for row in compiler.results_iter(results): web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 844, in results_iter web_1 | for rows in results: web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1289, in cursor_iter web_1 | sentinel): web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1288, in <lambda> web_1 | for rows in iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)), web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 101, in inner web_1 | return func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/utils.py", line 6, in utc_tzinfo_factory web_1 | raise AssertionError("database connection isn't set to UTC") web_1 | AssertionError: database connection isn't set to UTC 關鍵字應該是:AssertionError: database connection isn't set to UTC

twtrubiks commented 3 years ago

@abc225313 我稍微測試了一下 只需要改成 psycopg2==2.8.6 就可以了哦(我已經 push 了) b5cdadef1be4

你應該是出在 docker 的問題. 你修改成 psycopg2==2.8.6 之後, 在資料夾路徑底下執行以下的指令

docker-compose down -v
docker-compose build --no-cache 
docker-compose up -d

之後再重新你之前的流程.