django-defender
django-defender copied to clipboard
Problem with non ascii username submission
python 2.7 Django 1.8.13 django-defender 0.4.2
I cannot cleanup username filed, because defender handle post data before form validation, so if user submit non ascii username - defender raise UnicodeEncodeError exception.
"utils.py", line 68, in get_username_blocked_cache_key
return "{0}:blocked:username:{1}".format(config.CACHE_PREFIX, username)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
It looks like .format() is chocking on unicode characters. It should be this instead.
return u"{0}:blocked:username:{1}".format(config.CACHE_PREFIX, username)
If you want to submit a PR with this fix, that would be very helpful. We should also add a unit test for usernames with non ascii characters.
Why not use from __future__ import unicode_literals
?
@jedie not sure, I have to admit I'm horrible when it comes to unicode. If you feel that is the best way, feel free to submit a PR, and we can fix.
Is this still a problem, or has it been fixed with one of the recent releases?
I'm not able to reproduce this on python2, it would be nice to know which username had been passed around, I tried also to add a failing test but the test is passing
hmm, maybe it was already fixed. It is probably a good idea to have a unit test with the unicode character as a regression test, incase we accidentally break it again in the future.
how to write 60° in python because ° sign show error Your submission contains non ASCII characters, we don't accept submissions with non ASCII characters for this challenge.