Skip to content Skip to sidebar Skip to footer

Unicodedecodeerror: 'utf-8' Codec Can't Decode Byte 0xb9 In Position 14: Invalid Start Byte

I am doing a File upload test with Django REST. Python3.6.2 Django1.11 djangorestframework==3.6.4 Excel-OSX 15.38(170902) OSX 10.12.6 It used to be done successfully with ordinary

Solution 1:

The default mode of opening files is "r" which means non-binary read. Python is assuming your file is a text (encoded) file and trying to decode the contents. But it isnt a text file - it's a binary data file.

Change:

open(str(settings.BASE_DIR) + '/apps/zipcodes/complete.xlsx')

to:

open(str(settings.BASE_DIR) + '/apps/zipcodes/complete.xlsx', 'rb')

and it will probably work.

Post a Comment for "Unicodedecodeerror: 'utf-8' Codec Can't Decode Byte 0xb9 In Position 14: Invalid Start Byte"