Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth not working on router #240

Closed
jhintr opened this issue Oct 9, 2021 · 4 comments
Closed

auth not working on router #240

jhintr opened this issue Oct 9, 2021 · 4 comments

Comments

@jhintr
Copy link

jhintr commented Oct 9, 2021

Sorry, I still have the same problem as #20 , only diff is

api = NinjaAPI(version="1.0.0", auth=django_auth)

what returned is:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
    all_issues = checks.run_checks(
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check
    for pattern in self.url_patterns:
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 598, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
    return import_module(self.urlconf_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/zhi/Code/cliche/Cliche/urls.py", line 22, in <module>
    path('api/', api.urls),
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/ninja/main.py", line 314, in urls
    self._validate()
  File "/Users/zhi/Code/cliche/venv/lib/python3.8/site-packages/ninja/main.py", line 398, in _validate
    raise ConfigError("\n".join(msg))
ninja.errors.ConfigError: Looks like you created multiple NinjaAPIs
To let ninja distinguish them you need to set either unique version or url_namespace
 - NinjaAPI(..., version='2.0.0')
 - NinjaAPI(..., urls_namespace='otherapi')
Already registered: ['api-1.0.0']

If I remove auth=django_auth, then will be ok, I do the searching and read the doc on routers, can't figure out why.

@vitalik
Copy link
Owner

vitalik commented Oct 9, 2021

Hi @jhintr
could you isolate this issue into separate repository or zip file so I can reproduce ?

stephenrauch added a commit to stephenrauch/django-ninja that referenced this issue Oct 9, 2021
@stephenrauch
Copy link
Contributor

@jhintr I think this is a duplicate of the #229. I also believe the error message you likely should be seeing is:

ninja.errors.ConfigError: Cookie Authentication must be used with CSRF. Please use NinjaAPI(csrf=True)

@jhintr
Copy link
Author

jhintr commented Oct 9, 2021

@vitalik pls check the zip file: ninja.zip

@stephenrauch I think you are right, I add csrf=True and everything is ok now, that should be the right error message.

Thank you both for replying.

@jhintr jhintr closed this as completed Oct 12, 2021
vitalik added a commit that referenced this issue Oct 12, 2021
Resolve #229 & #240 reporting dev errors under django dev-server
@vitalik
Copy link
Owner

vitalik commented Oct 12, 2021

@jhintr Please try latest (0.16.1) version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants