question:UnicodeDecodeError at /admin/blog/author/import/
See original GitHub issueSir,thanks a lot to develop this great repository. I have little problem to solve , as below the code:
#in models.py
class Author(models.Model):
author = models.CharField('作者', max_length=50)
title = models.CharField('标题', max_length=150)
qualification = models.ForeignKey(Qualification)
mark = models.ManyToManyField(Mark)
blog = models.TextField('博客内容')
time = models.DateField('写作日期')
def __unicode__(self):
return unicode(self.author)
class Meta:
ordering = ['time']
#in admin.py
class AuthorAdmin(ImportExportModelAdmin, admin.ModelAdmin):
search_fields = ('author', 'title', 'mark', 'blog')
list_display = ('author', 'title', 'time')
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
Issue Analytics
- State:
- Created 10 years ago
- Comments:31 (15 by maintainers)
Top Results From Across the Web
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff ...
The question mark can be encoded/decoded using ASCII, UTF-8, Latin-1 and many more encodings without problems, so I don't see how it could...
Read more >UnicodeDecodeError in for loop - GIS Stack Exchange
I solved the issue with the following code: for row in csvReader: row = [unicode (r, errors = "replace") if type (r) ==...
Read more >'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
UnicodeDecodeError : 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte solved in Django . ... Problem Solving Point.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Then we point the new class as IMPORT_EXPORT_TMP_STORAGE_CLASS in settings.py:
Fixed in 0.3. please reopen if needed