mbi / django-simple-captcha

Django Simple Captcha is an extremely simple, yet highly customizable Django application to add captcha images to any Django form.
http://django-simple-captcha.readthedocs.io/en/latest/
MIT License
1.38k stars 324 forks source link

Weird characters on Debian #23

Open osam opened 11 years ago

osam commented 11 years ago

It working correctly on my development machine but when I deployed the app I got these weird characters from nowhere, as you can see from this image:

Screen Shot 2013-01-17 at 2 47 55 AM

This is my PIL log:

--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.3 (default, Dec  2 2012, 14:33:47)
              [GCC 4.4.5]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------

Your help would be appreciated.

mbi commented 11 years ago

Interesting.

Could it be you are using a different font set between dev and production? Also, what is the character encoding of either installations?

osam commented 11 years ago

Could it be you are using a different font set between dev and production?

No but when I faced the problem I tried to change the default font and that didn't solve the problem.

what is the character encoding of either installations?

Character encoding of what exactly?

mbi commented 11 years ago

Sorry, the default text encoding, i.e. the output of:

>>> import sys
>>> sys.getdefaultencoding()
mbi commented 11 years ago

Also, are you using a custom generator, or is that the default simplemath generator? See, I think the weird chars before each valid char are due to the fact that PIL (or freetype2) receives an Unicode string (or other encoded multi-byte chars) and misinterprets those as multiple chars.

If this is indeed a custom generator, could you please try and force the returned bits to string?

osam commented 11 years ago

~$ python Python 2.7.3 (default, Dec 2 2012, 14:33:47) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import sys sys.getdefaultencoding() 'ascii'

are you using a custom generator, or is that the default simplemath generator?

The default but it has nothing to do with the math generator per se I think. I am also getting the rectangles with the letter based captchas. I fixed it temporarily by removing the spaces from ' %s ': https://github.com/mbi/django-simple-captcha/blob/master/captcha/views.py#L52-L54

I had to switch to the letter mode because operators + / * - where also showing as rectangles.