question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion:The encode conversion

See original GitHub issue

Sir,I think over this question in django

UnicodeDecodeError at /admin/core/book/import/
'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte

then I use vim set fileencoding,I found the csv standard of file exported from the django-import-export is UTF-8,I search it on internet,I also found that if i use utf-8 standard file to import,it’s OK.

Maybe I use the OS in Chinese language so it cause the problem.Would you please modify the project:If the encode of import-file or export-file is not utf-8,first convert it to utf-8,then process other code?

I have write some code to fix the encode convertion:

import chardet

def convertEncoding(from_encode,to_encode,old_filepath,target_file):
    f1=file(old_filepath)
    content2=[]
    while True:
        line=f1.readline()
        content2.append(line.decode(from_encode).encode(to_encode))
        if len(line) ==0:
            break

    f1.close()
    f2=file(target_file,'w')
    f2.writelines(content2)
    f2.close()

convertFile = open('1234.csv','r')
data = convertFile.read()
convertFile.close()

convertEncoding(chardet.detect(data)['encoding'], "utf-8", "1234.csv", "1234_bak.csv")

I am a newbie , my code is not concise.would you please think about that and integrite the regular to the project?I very like this project,thanks for your reputation!

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
GabrieleCalarotacommented, May 25, 2020

Me too

Imported file has a wrong encoding: 'ascii' codec can't decode byte 0xc3 in position 31: ordinal not in range(128)

Can’t get it parsed with utf-8 in deploy environment, although in development works fine

2reactions
xiubinzhengcommented, Oct 3, 2019

Hi guys, Any updates on this, currently experiencing similar issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Character encoding conversion - EMVLab
From text. From hex (ASCII) From hex (EBCDIC), To text. To hex (ASCII) To hex (EBCDIC), With spaces. No spaces. C literal ...
Read more >
UndefinedConversionError: U+03B1 from UTF-8 to ISO-8859 ...
Method fails due to Encoding::UndefinedConversionError: U+03B1 from UTF-8 to ISO-8859-1 · Ask Question. Asked 9 years, 5 months ago. Modified 9 ...
Read more >
Character encoding and locales - Philip Withnall
The problem with the first is that iconv will stop converting when it encounters something it can't convert. The problem with the second...
Read more >
An Introduction to Arithmetic Coding
Arithmetic coding is a data compression technique that encodes data (the data string) by ... values of higher-order bits until a 0 is...
Read more >
Version History: ConvertXtoHD - VSO Software
[Bug] conversion stops at around 90% during menu encoding ... [Suggestion] The thumbnail frames should have all sides of equal thickness.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found