garyburgmann / drf-firebase-auth

Firebase backend to receive a user idToken and authenticate via Django REST Framework 'authentication.BaseAuthentication'. Optionally, a new local user can be created in the process.
MIT License
128 stars 62 forks source link

ImportError fix #39

Open boburxon opened 2 years ago

boburxon commented 2 years ago

Removed unused smart_text import from the authentication.py. This line causes ImportError on Django 4.0

ghost commented 2 years ago

Has there been any update on this issue? I am also stuck on the same issue:

(proj-env) user01@apu proj % python3 manage.py migrate drf_firebase_auth
Traceback (most recent call last):
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/settings.py", line 177, in import_from_string
    return import_string(val)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/utils/module_loading.py", line 15, in cached_import
    import_module(module_path)
  File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/var/proj/proj-env/lib/python3.9/site-packages/drf_firebase_auth/authentication.py", line 11, in <module>
    from django.utils.encoding import smart_text
ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (/var/proj/proj-env/lib/python3.9/site-packages/django/utils/encoding.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/proj/manage.py", line 21, in <module>
    main()
  File "/var/proj/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/base.py", line 90, in wrapped
    res = handle_func(*args, **kwargs)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 75, in handle
    self.check(databases=[database])
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/management/base.py", line 438, in check
    all_issues = checks.run_checks(
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/checks/registry.py", line 77, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/urls/resolvers.py", line 446, in check
    for pattern in self.url_patterns:
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/urls/resolvers.py", line 632, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/proj/proj-env/lib/python3.9/site-packages/django/urls/resolvers.py", line 625, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/var/proj/proj/urls.py", line 1, in <module>
    from builder.views import GenerateFlavorAndUpload, VerifyImageAccess, VerifyPortalName, RunJob, \
  File "/var/proj/builder/views.py", line 10, in <module>
    from rest_framework.views import APIView
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/views.py", line 17, in <module>
    from rest_framework.schemas import DefaultSchema
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/schemas/__init__.py", line 33, in <module>
    authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/settings.py", line 225, in __getattr__
    val = perform_import(val, attr)
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/settings.py", line 168, in perform_import
    return [import_from_string(item, setting_name) for item in val]
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/settings.py", line 168, in <listcomp>
    return [import_from_string(item, setting_name) for item in val]
  File "/var/proj/proj-env/lib/python3.9/site-packages/rest_framework/settings.py", line 180, in import_from_string
    raise ImportError(msg)
ImportError: Could not import 'drf_firebase_auth.authentication.FirebaseAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (/var/proj/proj-env/lib/python3.9/site-packages/django/utils/encoding.py).
boburxon commented 2 years ago

Deleting the unused import will resolve the issue, you can fork the repo and use it in your requirements.txt to install fixed version