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
question:UnicodeDecodeError at /admin/blog/author/import/ #72
Comments
What |
Sir,I download it from pip and the latest version is 0.9.11,I also download it from github,the zip files, also is the 0.9.11,so the problem still exist,is there any other tablib version?thanks for your concern. |
You can install development version with pip install -e git+https://github.com/kennethreitz/tablib.git#egg=tablib |
Development version of tablib shows itself as 0.9.11. |
Sir the emported file is also not correct.I paste the import process's traceback:
|
Exception shows path starting with "C:\Python27\lib\site-packages" while installed tablib shows path "/Users/allenlee/PycharmProjects/". Can you try to export and import using tablib (without using django-import-export) where is error comeing from. |
Hello Sir,I sometimes use OS-Windows to modify the code.So the path will not be consistent. I test the tablib #coding:utf-8
import tablib
data = tablib.Dataset(headers=['name', 'address', 'sex'])
data.append(['Lucy', 'ACT Australian Capital Territory', 'female'])
data.append(['Allen', ' NSW New South Wales', 'male'])
data.append(['何必见戴', ' SA South Australia', 'male'])
print data.csv and the output is ok
I think it maybe the unicode error?When I only use english and digital it will be ok to import and export.But when I use chinese words it will cause the error. |
Can you append data directly from model (this data that was corrupted) and regards |
Hello Sir,I try it in the django console,it is ok to export,and the Chinese words can be correctly appear. import tablib
from blog.models import Author
data = tablib.Dataset()
data.headers = ['id', 'author', 'title', 'qualification', 'mark', 'blog', 'time']
Author_list = Author.objects.all()
for Author_unit in Author_list:
data.append([Author_unit.id, Author_unit.author, Author_unit.title,
Author_unit.qualification, Author_unit.mark, Author_unit.blog, Author_unit.time])
print data.csv output is
|
can you write this file to disk and diff with exported file from admin regards |
I just made a test by adding "何必见戴" string to Book instance in a example app, that is bundled with django-import-export. Both import and export worked without any errors. Please, try reproducing issue with import-export example app. |
OK,thanks a lot for your concern. |
Sir,I think over this question in django
then I use vim Maybe I use the OS in Chinese language so it cause the problem.Would you please modify the project:If the encode of Thanks for your concern. |
i'm running into the same problem with a csv. It appears that for Python 2.7, "from_encoding" is not relevant to an import, as CSV.is_binary() returns as True, during the check in ImportMixin.import_action(). |
OK, we need failing test for this. |
This is not a test, but a step towards one: the file i was working with at the time choked on these characters: 0x96, 0xae, 0x99, 0xa0. 0x96 is an en-dash in windows (U+2013). i discovered that i was able to read the file using encoding "Windows-1252". Or by using 'ignore' and 'replace' when decoding as utf-8, which have their own drawbacks.
|
The issue is reading it in universal newline mode. This line represents a way that is compatible with unicode. |
pull request with and test would be welcomed :) |
or at least failing test |
Not sure if this is relevant. http://pastebin.com/ivXprEhp
Seems to me that this problem should just show up whenever you try to import data? Export works fine for me. |
I would really like to fix this but need to be able to reproduce this issue. Creating file with bundled example application |
Can not reproduce in example app. It is a mystery. |
I can confirm that it had something to do with the unicode method on my model. Which is really very strange, since it seems to show up alright in the admin interface proper. Wish I was working on something open source right now, so I could just show you the code. My unicode method looked like
and now it looks like
Everything seems to be working. I'm going to guess that this probably wasn't the same error everyone else was having. But hopefully this will help other people. Be forewarned, sometimes your models unicode method with break django-import-export it hard to diagnose ways. |
@traverseda, should't it be:
Note |
That explains it. I am not a clever man. Thanks. Why it wasn't throwing an error earlier (in the admin interface, or my other export script) I don't know. |
Regarding errors and debugging, django-import-export will display traceback when some error occur allowing to insert |
Hi guys, I've stumbled upon the exact same issue in one of my company's projects. We're using python3 and I'm 100% sure there's no u' missing on any model's __ str__ method. Yet, the UnicodeDecodeError exception still occurs when trying to import a csv file containing utf-8 encoded characters in the django admin. It turns out that adding the encoding param with value of utf-8 to the TempFolderStorage.open's method seems to solve the problem, at least in our environment. Here's a quick'n'dirty fix in case anyone googles this issue trying to find a solution, like I did a few hours ago. First we subclass the TempFolderStorage class, adding said param: import tempfile
from import_export.tmp_storages import TempFolderStorage
class Utf8TempFolderStorage(TempFolderStorage):
def open(self, mode='r'):
if self.name:
return open(self.get_full_path(), mode, encoding='utf-8')
else:
tmp_file = tempfile.NamedTemporaryFile(delete=False)
self.name = tmp_file.name
return tmp_file Then we point the new class as IMPORT_EXPORT_TMP_STORAGE_CLASS in settings.py: IMPORT_EXPORT_TMP_STORAGE_CLASS = 'path.to.storages.Utf8TempFolderStorage' |
@pawelnowak this should be bug introduced in 0.2.9 - it is explained here: can you please check if fix works for you? |
Fixed in 0.3. please reopen if needed |
Sir,thanks a lot to develop this great repository.
I have little problem to solve , as below
the code:
When I export the data,
but the csv file appear to be the retortion,
when I modified the second row author data and import,
it cause the error,
how I it be smoothly modified and import?thanks.
Allenlee
The text was updated successfully, but these errors were encountered: