Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ascii' codec can't decode byte error when using collate utf8_bin in mysql #280

Closed
cimani opened this issue Dec 21, 2014 · 4 comments
Closed

Comments

@cimani
Copy link

cimani commented Dec 21, 2014

When I am using mysql collate utf8_bin on tag name field and have tag names with unicode characters such as á, django template throws DjangoUnicodeDecodeError in force_unicode(value):

'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128). You passed in <Tag: [Bad Unicode data]> (<class 'taggit.models.Tag'>)

Replacing tag name column collate utf8_bin with utf8_general_ci fixes this issue but raises a different issue with IntegrityError when trying to save tags with different casing.

I have added a fix in my fork which solves the issue in my scenario by making sure the str function always returns unicode by casting to utf8 if mysqldb returns byte string: cimani@bf26627

I would love for this fix to go into the master but I do realize that this changes forces utf8 which might not apply to all applications of this awesome plugin. I am guessing making encoding as an optional parameter passed through TaggableManager init function and applied to the underlying tag class to be used by this function would be one way around this. But I am not exactly sure how to implement this in a nice and clean way yet. If anyone has any good ideas on this, please point me to right direction :)

@hoffmannkrzysztof
Copy link

Check your MySQL-python version. It should be 1.2.5. I had similar problem and this fixed my problem.

@frewsxcv
Copy link
Collaborator

I strongly recommend people using mysql-python to use https://pypi.python.org/pypi/mysqlclient instead. It's a fork that's well maintained and has python 3 support. Django recommends it now.

@collinanderson
Copy link
Contributor

ditto to mysqlclient

@rtpg
Copy link
Contributor

rtpg commented Apr 14, 2021

closing as this seems to be a mysql thing

@rtpg rtpg closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants