[Python] Can't find proper encoding to open old ascii-encoded DBF files with Slovak, Czech,...

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with a few old DBF files that contain special characters from the Slovak, Czech, and German alphabets (e.g., š, č, ř, ä, ö, ü). Both Python libraries dbfread and dbf indicate that the encoding is ASCII.

    Type:Foxpro
    Codepage: ascii (plain ol' ascii)
    Status:0


    Reading the file using ASCII encoding throws an error:

    Error reading file ...: 'ascii' codec can't decode byte 0xe8 in position 2: ordinal not in range(128)


    Using "char_decode_errors='ignore'" simply removes the problematic characters.

    I have tried the following encodings without success:

    1. utf-8
    2. cp1250 (Central European)
    3. cp852 (Latin-2)
    4. iso-8859-2 (Latin Alphabet No. 2)
    5. cp437 (OEM United States)
    6. cp850 (OEM Multilingual Latin 1)
    7. latin_1 (ISO-8859-1)
    8. mbcs (Multibyte Character Set - system default)

    mbcs seems to be the closest but still not 100%. Other DBF files encoded with cp1250 and cp852 don't throw UnicodeDecodeError when read with the original encoding.

    Continue reading...

Compartilhe esta Página