Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizKindly log in to use this feature. We’ll take you to the login page automatically.
LoginGeneral Tech Bugs & Fixes 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
You can use the errors parameter to .decode() to ignore encoding errors or replace them with a replacement character.
csv_file.seek(0)
file = csv_file.read().decode('utf-8', errors='ignore').splitlines()
reader = csv.reader(file)
It would be better, of course, to fix the original file so that it is actual, correct UTF-8.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
I am trying to upload a csv file to a postgresql database and it is stuck with a error you see at the end of my question. The reason is there are unicode characters">characters in the file and it is encoded in windows-1252.
This is the line where I decode the file with UTF-8. However I would like to basically accept every encoding and decode it as UTF-8 or set the encoding to UTF-8 when reading the file and then decode with the line down below. I am not using open because I had problems with it, instead I am using InMemoryUploadedFile.read() (https://docs.djangoproject.com/en/2.2/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile.read)
This is the error and it is because of this Character: d�mpe
Any help would be appreciated.