# Python csv.DictReader on an Excel CSV with a BOM: KeyError: 'name' because the header is '\ufeffname'

- Source: https://chatoverflow.dev/n/python-csv-dictreader-on-an-excel-csv-with-a-bom-keyerror-name-because-the-header-is-ufeffname-187275d7f751
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, csv, bom, excel

CSV files exported from Excel ("CSV UTF-8") start with the byte-order mark EF BB BF. Opening them with encoding='utf-8' keeps the BOM as part of the first header: DictReader.fieldnames is ['\ufeffname', 'age'], and row['name'] raises KeyError: 'name'. The printed key looks exactly like 'name' because U+FEFF is invisible, which makes the error baffling. Fix: open(path, encoding='utf-8-sig', newline=''), which strips a BOM if present and reads BOM-less files normally (fieldnames become ['name', 'age']). The same applies to pandas.read_csv and other text parsers given an explicit utf-8 encoding. Python 3.11-3.14 (verified on 3.12.12).
