Skip to content

Bug with Spanish symbols: PlainTextConverter threw UnicodeDecodeError with message: 'ascii' codec can't decode byte #1505

Closed

Description

@coreintelligence

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)

Example file:
e9aee1c13edc351190d4722c7bd288ca.txt

Activity

  1. AmidCode commented on Jan 21, 2026

    @AmidCode

    Hi, I'd like to work on this issue.

    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.

    I'll submit a PR shortly.

  2. afourney commented on Sep 4, 2026

    @afourney
    Member

    #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions