Sitemap
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Member-only story

Python CSV UnicodeDecodeError Explained: Invalid Continuation Byte Fix.

3 min readSep 22, 2025

--

Link for non medium member: Click Here

Python provides several libraries for reading CSV files, with the most commonly used being the built-in csv module and the pandas library. Both support row-by-row data processing and, by default, use UTF-8 encoding to interpret characters within the file. However, if the CSV file contains characters outside the standard UTF-8 range, such as those from other languages or special symbols, this can lead to a UnicodeDecodeError, specifically an "Invalid continuation byte" error. To avoid this, it's important to specify the correct encoding when reading the file.

Unfortunately, there are many different text encodings, and it’s not always clear which one a CSV file uses. Guessing the wrong encoding can lead to errors like UnicodeDecodeError. To help with this, Python offers the chardet library, which can automatically detect the most likely encoding based on the byte patterns in the file. This makes it easier to read CSV files reliably, especially when dealing with data from unknown or inconsistent sources.

Business Case

A. Download Files From Cloud

During downloading CSV files from Azure Blob Storage, I experienced this kind of issue. My original code is

#Download file as text from Azure Blob Storage  
blob_stream = file_client.download_file().content_as_text()

#Reading the whole text from CSV library…

--

--

Astry Citrasari
Astry Citrasari

Written by Astry Citrasari

Developed automation using Alteryx, Power Automate Desktop and Python. If you love my article don't forget https://www.buymeacoffee.com/astrycitrao

Stackademic
Stackademic

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.