InventorLoader icon indicating copy to clipboard operation
InventorLoader copied to clipboard

unknown encoding: ansi

Open lukecyca opened this issue 7 months ago • 0 comments

When I attempt to load a .f3d file, I get the following traceback:

21:20:24  pyException: Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.11/site-packages/freecad/module_io.py", line 16, in OpenInsertObject
    getattr(importerModule, importMethod)(objectPath, *importArgs, **importKwargs)
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerIL.py", line 148, in open
    _open(abs_file_name, skip, only, root)
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerIL.py", line 127, in _open
    reader = read(filename)
             ^^^^^^^^^^^^^^
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerIL.py", line 70, in read
    if (importerF3D.read(filename)):
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerF3D.py", line 168, in read
    folder = read_manifest(f3d, 'Manifest.dat')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerF3D.py", line 120, in read_manifest
    t, i = getLen32Text8(data, i)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerUtils.py", line 886, in getLen32Text8
    txt, i = getText8(data, i, l)
             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/luke/Library/Application Support/FreeCAD/Mod/InventorLoader/./importerUtils.py", line 869, in getText8
    txt = data[i: end].decode('ansi')
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
<class 'LookupError'>: unknown encoding: ansi

I am running InventorLoader 1.5.1 on FreeCAD 1.0.1.39285 on macOS 14.7.5.

According to this stackoverflow, ansi is a slightly-ambiguous Windows encoding that differs somewhat by region but generally refers to an encoding that is more precisely referred to as cp1252. For whatever reason, ansi doesn't work in non-Windows builds of Python, but cp1252 does. So I would propose we change this line to use .decode('cp1252').

lukecyca avatar Jun 11 '25 04:06 lukecyca