안녕하세요? 강의 잘 듣고 있습니다.
강의 11분경 즈음 rest_framework_jwt에러가 발생합니다
가상환경에 알맞게 설치되었는지는 확인했고 / 혹시나 해서 pip uninstall후 다시 install까지 해봣는데도 에러가 발생하네요
찾아보니까 simple-jwt를 써보라는데, 그것도 안되는 것 같았습니다 ㅠ
우선 제 settings.py입니다
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
],
그리고 이렇게 해둔 상태에서 runserver를 cmd에서 돌리니까
다음과 같은 에러가 cmd에서 발생합니다.
(askcompany) C:\Users\user\yb\django_askcompany\askcompany\Scripts\_askcompany8>python manage.py runserver Watching for file changes with StatReloader Performing system checks... Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\settings.py", line 177, in import_from_string return import_string(val) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\module_loading.py", line 30, in import_string return cached_import(module_path, class_name) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\module_loading.py", line 15, in cached_import import_module(module_path) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework_jwt\authentication.py", line 4, in <module> from django.utils.encoding import smart_text ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\encoding.py) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner self.run() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run self._target(*self._args, **self._kwargs) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\core\management\commands\runserver.py", line 124, in inner_run self.check(display_num_errors=True) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\core\management\base.py", line 438, in check all_issues = checks.run_checks( File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\core\checks\registry.py", line 77, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config return check_resolver(resolver) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver return check_method() File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\urls\resolvers.py", line 448, in check for pattern in self.url_patterns: File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\urls\resolvers.py", line 634, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\urls\resolvers.py", line 627, in urlconf_module return import_module(self.urlconf_name) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\user\yb\django_askcompany\askcompany\Scripts\_askcompany8\_askcompany8\urls.py", line 7, in <module> path('accounts/', include('accounts.urls')), File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\urls\conf.py", line 34, in include urlconf_module = import_module(urlconf_module) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\user\yb\django_askcompany\askcompany\Scripts\_askcompany8\accounts\urls.py", line 1, in <module> from rest_framework.authtoken.views import obtain_auth_token File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\authtoken\views.py", line 6, in <module> from rest_framework.schemas import ManualSchema File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\schemas\__init__.py", line 33, in <module> authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES, File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\settings.py", line 225, in __getattr__ val = perform_import(val, attr) File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\settings.py", line 168, in perform_import return [import_from_string(item, setting_name) for item in val] File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\settings.py", line 168, in <listcomp> return [import_from_string(item, setting_name) for item in val] File "C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\rest_framework\settings.py", line 180, in import_from_string raise ImportError(msg) ImportError: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (C:\Users\user\yb\django_askcompany\askcompany\lib\site-packages\django\utils\encoding.py).
가상환경에서 사용되는 버전은 다음과 같습니다.
늘 빠르고 친절한 답변에 감사드립니다.
토큰이 만료되었을 경우 401 응답을 받을 수 있습니다.
이 모든 것이 실력향상의 밑거름이 되실 것입니다. 화이팅입니다. :-)