You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug with Spanish symbols: PlainTextConverter threw UnicodeDecodeError with message: 'ascii' codec can't decode byte #1505
Hi, I was trying to use markitdown's convert function with some files and I noticed that it threw an error for certain symbols. I've attached both the error and an example file.
Source used to generate bug:
from markitdown import MarkItDown
md = MarkItDown()
result = md.convert("./e9aee1c13edc351190d4722c7bd288ca.txt")
print(result.text_content)
Error:
markitdown._exceptions.FileConversionException: File conversion failed after 1 attempts:
- PlainTextConverter threw UnicodeDecodeError with message: 'ascii' codec can't decode byte 0xc3 in position 4101: ordinal not in range(128)
Root Cause:
The charset detection in _markitdown.py samples only the first 4096 bytes of a file. When these bytes are ASCII-only but later bytes contain UTF-8 characters (like Spanish accented characters é, ñ, or CJK characters), the charset is incorrectly detected as ascii, causing UnicodeDecodeError when decoding the full file.
Proposed Fix:
Add a fallback mechanism in PlainTextConverter.convert() that catches UnicodeDecodeError and re-detects the charset using charset_normalizer on the full file content.
Test Coverage:
Added parametrized tests for Spanish, Korean, Japanese, and Chinese text to ensure the fix works across different languages.
#2360 substantially increased the charset-detection window and added better handling and diagnostics for incorrect ASCII guesses, which should address this report. Since the original reproducer is no longer available, I’m closing this as likely resolved. Please reopen with a sample file that still fails against 0.1.8b1 or later.
Activity
AmidCode commentedon Jan 21, 2026
Hi, I'd like to work on this issue.
Root Cause:
The charset detection in
_markitdown.pysamples only the first 4096 bytes of a file. When these bytes are ASCII-only but later bytes contain UTF-8 characters (like Spanish accented characters é, ñ, or CJK characters), the charset is incorrectly detected asascii, causingUnicodeDecodeErrorwhen decoding the full file.Proposed Fix:
Add a fallback mechanism in
PlainTextConverter.convert()that catchesUnicodeDecodeErrorand re-detects the charset usingcharset_normalizeron the full file content.Test Coverage:
Added parametrized tests for Spanish, Korean, Japanese, and Chinese text to ensure the fix works across different languages.
I'll submit a PR shortly.
fix: Handle UnicodeDecodeError in PlainTextConverter (microsoft#1505)
style: fix linting (microsoft#1505)
chore: Include charset fallback test in `__main__` runner (microsoft#…
fix: Handle UnicodeDecodeError in PlainTextConverter (microsoft#1505)
afourney commentedon Sep 4, 2026
#2360 substantially increased the charset-detection window and added better handling and diagnostics for incorrect ASCII guesses, which should address this report. Since the original reproducer is no longer available, I’m closing this as likely resolved. Please reopen with a sample file that still fails against 0.1.8b1 or later.