The apkgs file exported from anki has a corrupted/binary “media” file

So, I tried to convert the anki apkgs file to xml by anki2sm program(GitHub - anki2smArchive/anki2sm: Anki2 to SuperMemo 17/18 collection converter), and when I tried to export my anki deck to apkgs file, then try to convert it, some error occurred:

Traceback (most recent call last):
  File "C:\anki2sm-master\anki2smV2.py", line 852, in <module>
    main()
  File "C:\anki2sm-master\anki2smV2.py", line 807, in main
    start_import(mypath + apkgfiles[I])
  File "C:\anki2sm-master\anki2smV2.py", line 457, in start_import
    media = unpack_media(p)
  File "C:\anki2sm-master\anki2smV2.py", line 181, in unpack_media
    m = json.loads(f.read())
  File "C:\Users\a1\AppData\Local\Programs\Python\Python39\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 1: invalid start byte
Press any key to continue . . .

Then I try to extract the apkgs file by rename it to .zip to see if the “media” file whether is json or UTF-8 encoding or not, then there’s only completely random words there

Like this:

But if I export the apkgs from a language learning software (lookupper) instead of anki, the file is normal and the process is fine and without any error, so I think the error came from my anki. I tried to

  • check the database and check the media
  • reinstall anki ( I don’t completely delete the deck file though)
  • update anki
  • simpler deck to export
  • I tried to switch to safe mode( seemingly switched)

All those just doesn’t work.

Anki Version ⁨25.02.6 (6381f184)⁩
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
Mac OS: 15.3 (24D60)

Grateful for any help.

APKG files are meant to be used for exporting and importing with Anki software. That’s the only thing we support. If an APKG isn’t working with a 3rd-party conversion tool, that’s an issue you should take up with the folks offering that tool.

1 Like

So I don’t know if it’s a normal situation that the “media” file which exported from anki is suppose to be binary or not, if so, I would contact the author of that tool, but if not, I wonder if I could fix that by asking the question here

If an APKG you created using Anki imports into Anki correctly, then there’s nothing wrong with the file. Have you tried that?

1 Like

No…Then I tried it, seems fine if I import the file which exported from anki.

well then, I tried to export the file without the option of including the scheduling information and with the option of support older version of anki, then it works…and thanks for your help though

2 Likes

Lookupper uses the older Anki 2.1 .apkg collection format, which is more compatible with most third-party tools.

The latest Anki uses a modern .apkg format, which — as @Danika_Dakika pointed out — is mainly designed for forward compatibility with modern Anki itself, not third-party tools.

So if you want to use older tools and keep a compatible .apkg file — as you already found out — you need to check the “support older Anki versions” box when exporting your collection.

3 Likes