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

following example for custom backend: no 'username' in request.POST #43

Open
mxork opened this issue Oct 15, 2018 · 0 comments
Open

following example for custom backend: no 'username' in request.POST #43

mxork opened this issue Oct 15, 2018 · 0 comments

Comments

@mxork
Copy link

mxork commented Oct 15, 2018

Following https://django-ratelimit-backend.readthedocs.io/en/latest/usage.html#customizing-rate-limiting-criteria

  File "/usr/local/lib/python3.7/site-packages/ratelimitbackend/backends.py", line 33, in authenticate
    counts = self.get_counters(request)
  File "/usr/local/lib/python3.7/site-packages/ratelimitbackend/backends.py", line 60, in get_counters
    return cache.get_many(self.keys_to_check(request))
  File "/usr/local/lib/python3.7/site-packages/ratelimitbackend/backends.py", line 68, in keys_to_check
    ) for minute in range(self.minutes + 1)
  File "/usr/local/lib/python3.7/site-packages/ratelimitbackend/backends.py", line 68, in <listcomp>
    ) for minute in range(self.minutes + 1)
  File ".../settings/ratelimit.py", line 15, in key
    return f'{request.POST[self.username_key][:max_username_length]}-{dt}'
  File "/usr/local/lib/python3.7/site-packages/django/utils/datastructures.py", line 79, in __getitem__
    raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'username'

from backends.py/RateLimitMixin:

    def authenticate(self, request=None, **kwargs):
        username = None
        try:
            username = kwargs[self.username_key]
        except KeyError:
            if not self.no_username:
                raise

So username is expected to be passed through **kwargs, not request. Can't make the example work without override-ing authenticate, get_counters, get_cache_key, key.

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

1 participant