From 2357a4616bd7e200f2d262d144f29dddddae7da5 Mon Sep 17 00:00:00 2001 From: Jorge Galvis Date: Tue, 6 Dec 2016 18:08:13 -0500 Subject: [PATCH] Make it Python3 compatible --- axes/decorators.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/axes/decorators.py b/axes/decorators.py index dacb324..de9c3af 100644 --- a/axes/decorators.py +++ b/axes/decorators.py @@ -476,6 +476,8 @@ def get_cache_key(request_or_object): :return cache-key: String, key to be used in cache system """ ua = None + ip = None + if isinstance(request_or_object, AccessAttempt): ip = request_or_object.ip_address ua = request_or_object.user_agent @@ -483,7 +485,10 @@ def get_cache_key(request_or_object): ip = get_ip(request_or_object) ua = request_or_object.META.get('HTTP_USER_AGENT', '')[:255] + ip = ip.encode('utf-8') + if ua: + ua = ua.encode('utf-8') cache_hash_key = 'axes-{}'.format(md5(ip+ua).hexdigest()) else: cache_hash_key = 'axes-{}'.format(md5(ip).hexdigest())