Skip to content

Commit

Permalink
See if this fixes the UnicodeDecodeError were getting
Browse files Browse the repository at this point in the history
  • Loading branch information
mbi committed Apr 2, 2015
1 parent 4952f86 commit d3cbccd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions captcha/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import datetime
import random
import time
import unicodedata
import six

# Heavily based on session key generation in Django
Expand Down Expand Up @@ -44,7 +43,11 @@ def save(self, *args, **kwargs):
if not self.expiration:
self.expiration = get_safe_now() + datetime.timedelta(minutes=int(captcha_settings.CAPTCHA_TIMEOUT))
if not self.hashkey:
key_ = unicodedata.normalize('NFKD', str(randrange(0, MAX_RANDOM_KEY)) + str(time.time()) + six.text_type(self.challenge)).encode('ascii', 'ignore') + unicodedata.normalize('NFKD', six.text_type(self.response)).encode('ascii', 'ignore')
key_ = (six.text_type(randrange(0, MAX_RANDOM_KEY)) +
six.text_type(time.time()) +
six.text_type(self.challenge) +
six.text_type(self.response)
).encode('utf8')
if hashlib:
self.hashkey = hashlib.sha1(key_).hexdigest()
else:
Expand Down

0 comments on commit d3cbccd

Please sign in to comment.