diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index e262b886b..86289409b 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -171,7 +171,7 @@ class AnonRateThrottle(SimpleRateThrottle): scope = 'anon' def get_cache_key(self, request, view): - if request.user.is_authenticated: + if request.user and request.user.is_authenticated: return None # Only throttle unauthenticated requests. return self.cache_format % { @@ -191,7 +191,7 @@ class UserRateThrottle(SimpleRateThrottle): scope = 'user' def get_cache_key(self, request, view): - if request.user.is_authenticated: + if request.user and request.user.is_authenticated: ident = request.user.pk else: ident = self.get_ident(request) @@ -239,7 +239,7 @@ class ScopedRateThrottle(SimpleRateThrottle): Otherwise generate the unique cache key by concatenating the user id with the '.throttle_scope` property of the view. """ - if request.user.is_authenticated: + if request.user and request.user.is_authenticated: ident = request.user.pk else: ident = self.get_ident(request)