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

UnicodeDecodeError with non-ASCII filenames for field type 'FILE' on Python 2 #188

Open
petrikoz opened this issue Sep 16, 2016 · 1 comment

Comments

@petrikoz
Copy link

Hello

I use your module of version 0.12.3 on Python 2 and MySQL as database.
And I have problem with fields with type 'FILE'.

When I upload files with non-ASCII characters in them names I have UnicodeDecodeError in MySQL save method.
This method try use value of field as bytes string.

It happen because your code convert value of field with type FILE is instance to future.types.newstr.newstr. And it doesn't convert to Python 2 unicode type as other values from form.

Can you help me solve this problem? Or maybe you show me where I must dig in my search?

@marcosguedes
Copy link

marcosguedes commented Feb 1, 2018

Hi. This is an ancient bug but I've crossed paths with this today and solved it using sys.setdefaultencoding('utf8')

PS: This method is highly discouraged but since I haven't found a way to fix this except creating a clone of/overriding forms_builder_tags.py, forms.py and views.py this'll have to do

inside settings.py

# -*- coding: utf-8 -*-
import os
import sys

# (...)

reload(sys)
sys.setdefaultencoding('utf8')

I hope this saves some hours of work to the people who came across this bug

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

2 participants