Why This Happens
The csv module in Python 3 works with text strings. If you open in binary mode, the reader receives bytes and raises this error.
The Problem
import csv
with open('data.csv', 'rb') as f:
reader = csv.reader(f)The Fix
import csv
with open('data.csv', 'r', encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
print(row)Step-by-Step Fix
- 1
Open in text mode
Use 'r' instead of 'rb'.
- 2
Specify encoding
Add encoding='utf-8'.
- 3
Handle BOM
Use encoding='utf-8-sig' for files with BOM.
Bugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free