ImportError:无法导入运行python manage.py的名称'ApiException'

时间:2019-11-05 13:18:53

标签: python django

我无法从rest_framework.exceptions导入ApiException

这是我的Exception.py:

class APIException(Exception):
    status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    default_detail = _('A server error occurred.')
    default_code = 'error'

    def __init__(self, detail=None, code=None):
        if detail is None:
            detail = self.default_detail
        if code is None:
            code = self.default_code

        self.detail = _get_error_details(detail, code)

    def __str__(self):
        return self.detail

    def get_codes(self):
        return _get_codes(self.detail)

    def get_full_details(self):
        return _get_full_details(self.detail)
error while running : python manage.py makemigrations networscanners 
    Traceback (most recent call last):
          File "manage.py", line 25, in <module>
            execute_from_command_line(sys.argv)
          File "D:\Python36-32\lib\site-packages\django\core\management\__init__.py", li
        ne 381, in execute_from_command_line
            utility.execute()
          File "D:\Python36-32\lib\site-packages\django\core\management\__init__.py", li
        ne 375, in execute
            self.fetch_command(subcommand).run_from_argv(self.argv)
          File "D:\Python36-32\lib\site-packages\django\core\management\base.py", line 3
        23, in run_from_argv
            self.execute(*args, **cmd_options)
          File "D:\Python36-32\lib\site-packages\django\core\management\base.py", line 3
        61, in execute
            self.check()
          File "D:\Python36-32\lib\site-packages\django\core\management\base.py", line 3
        90, in check
            include_deployment_checks=include_deployment_checks,
          File "D:\Python36-32\lib\site-packages\django\core\management\base.py", line 3
        77, in _run_checks
            return checks.run_checks(**kwargs)
          File "D:\Python36-32\lib\site-packages\django\core\checks\registry.py", line 7
        2, in run_checks
            new_errors = check(app_configs=app_configs)
          File "D:\Python36-32\lib\site-packages\django\core\checks\urls.py", line 13, i
        n check_url_config
            return check_resolver(resolver)
          File "D:\Python36-32\lib\site-packages\django\core\checks\urls.py", line 23, i
        n check_resolver
            return check_method()
          File "D:\Python36-32\lib\site-packages\django\urls\resolvers.py", line 400, in
         check
            for pattern in self.url_patterns:
          File "D:\Python36-32\lib\site-packages\django\utils\functional.py", line 80, i
        n __get__
            res = instance.__dict__[self.name] = self.func(instance)
          File "D:\Python36-32\lib\site-packages\django\urls\resolvers.py", line 585, in
         url_patterns
            patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
          File "D:\Python36-32\lib\site-packages\django\utils\functional.py", line 80, i
        n __get__
            res = instance.__dict__[self.name] = self.func(instance)
          File "D:\Python36-32\lib\site-packages\django\urls\resolvers.py", line 578, in
         urlconf_module
            return import_module(self.urlconf_name)
          File "D:\Python36-32\lib\importlib\__init__.py", line 127, in import_module
            return _bootstrap._gcd_import(name[level:], package, level)
          File "<frozen importlib._bootstrap>", line 994, in _gcd_import
          File "<frozen importlib._bootstrap>", line 971, in _find_and_load
          File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
          File "<frozen importlib._bootstrap_external>", line 678, in exec_module
          File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
          File "D:\archerysec framework\archerysec-master\archerysecurity\urls.py", line
         36, in <module>
            from rest_framework_jwt.views import obtain_jwt_token, verify_jwt_token
          File "D:\Python36-32\lib\site-packages\rest_framework_jwt\views.py", line 1, i
        n <module>
            from rest_framework.views import APIView
          File "D:\Python36-32\lib\site-packages\rest_framework\views\__init__.py", line
         1, in <module>
            from .base import BaseApiView
          File "D:\Python36-32\lib\site-packages\rest_framework\views\base.py", line 5,
        in <module>
            from rest_framework.exceptions import ApiException
        ImportError: cannot import name 'ApiException'

1 个答案:

答案 0 :(得分:0)

它是 APIException rest_framework.exceptions.APIException),而不是ApiException