Import failed. Invalid input: ⁨Field name: #⁩

Hey everyone,

I stumbled over the shared deck of number: 2020743342
When I tried to import it I got the following error message:
Invalid input: Field name: # (I hope the mark up works here)

I tried importing this file on the Anki app for iPhone, and the two Linux versions 2.1.54 and 2.1.66. The second is at the time of posting this question the most current version. In all three versions, I get the same error in all three versions. I will post a bit more about the terminal output later, but I guess either the deck is somehow broken or something with the parsing is wrong. It should be mentioned that this deck includes words written in Farsi i.e., the Persian alphabet.

If anyone has suggestions on what the problem is or just where to start debugging and how I would highly appreciate any advice.

Now also some debug output from the terminal

For version 2.1.66 I get the following error output when trying to import the deck:

Traceback (most recent call last):
  File "aqt.mediasrv", line 566, in wrapped
  File "aqt.mediasrv", line 460, in import_anki_package
  File "aqt.mediasrv", line 442, in import_request
  File "aqt.mediasrv", line 547, in <lambda>
  File "anki._backend_generated", line 1624, in import_anki_package_raw
  File "anki._backend", line 151, in _run_command
anki.errors.InvalidInput: Field name: #

JS error /_anki/pages/import-log.js:1 Uncaught (in promise) Error: 500: Field name: #

For version 2.1.54 I get the following output:

Traceback (most recent call last):
  File "aqt.importing", line 387, in on_done
  File "concurrent.futures._base", line 439, in result
  File "concurrent.futures._base", line 391, in __get_result
  File "concurrent.futures.thread", line 58, in run
  File "anki.importing.apkg", line 50, in run
  File "anki.importing.anki2", line 54, in run
  File "anki.importing.anki2", line 78, in _import
  File "anki.importing.anki2", line 116, in _importNotes
  File "anki.importing.anki2", line 204, in _uniquifyNote
  File "anki.importing.anki2", line 242, in _mid
  File "anki.models", line 542, in update
  File "anki._backend.generated", line 861, in add_or_update_notetype
  File "anki._backend", line 146, in _run_command
anki.errors.InvalidInput: Invalid input: <U+2068>Field name: #<U+2069>

# is a special character and is not valid in field names. Anki fixes field names automatically by stripping such characters, but that’d result in an empty name in this case, so an error is thrown.

Thanks a lot for this reply and explanation.
How can I fix this then?
I guess I need to manually replace this character with a different character to fix the deck.
So far, I unzipped the file and accessed the collection file with sqlite3, but I am new to that. Do you by chance know how to move around in that program?

Ok I managed to repair it manually.
So the APKG file is actually nothing more than a ZIP archive, but inside this archive are only the files “collection.anki2” and “media”. So after renaming the APKG file to a ZIP file and unpacking it, you can check out the “collection.anki2” file. This file is a SQLite3 database.
To manipulate the database I installed sqlitebrowser on my system, but I guess whatever SQLite-Browser you have should work.
As abdo already correctly stated, # is a special character and invalid as a field name so I searched were it occurred. In my case it was in table “col” and field “models”. The table only had one row and for this, the field “models” had some JSON stuff written into it, which looked like the JSON code for describing a self-written card type. The card type had “#” written as the field name, which I just changed to “Number”. After saving the database file and wrapping up everything again as it should be. The import worked and I could see and use the cards normally.

If you get an error like “Error: 500: specified file not found in archive” it means you did not wrap it up correctly. Check that the filenames have the correct file extensions again (.anki2 and .apkg) and that the archive holds “collection.anki2” and “media” directly and not in a subfolder.

Hope this helps some people :slight_smile:

1 Like