Anki CSV Importer not working - KeyError: 'Front'

I am trying to use the Anki CSV Importer to import a CSV file I have into an Anki deck.

My CSV file has 2 columns (Back, Front) and, as of right now, 2628 rows (whose number will grow with time), looking like this:

Back, Front
translation1,word1
translation2,word2
[etc]

I have added the AnkiConnect add-on to Anki, as recommended by the author of the code on GitHub (I am running it on Windows 11).

I am also ensuring an instance of Anki is running before executing the Anki CSV importer.

My program crashes, here is the exception I am getting:

Starting main loop...
JS error :1 Uncaught TypeError: Cannot read properties of null (reading 'offsetHeight')
  File "<string>", line 1, in <module>
  File "aqt", line 509, in run
  File "aqt", line 717, in _run
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\__init__.py", line 93, in advance
    self.server.advance()
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\web.py", line 136, in advance
    self.advanceClients()
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\web.py", line 151, in advanceClients
    self.clients = list(filter(lambda c: c.advance(), self.clients))
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\web.py", line 151, in <lambda>
    self.clients = list(filter(lambda c: c.advance(), self.clients))
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\web.py", line 68, in advance
    self.writeBuff += self.handler(req)
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\web.py", line 202, in handlerWrapper
    body = json.dumps(self.handler(params)).encode('utf-8')
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\__init__.py", line 130, in handler
    api_return_value = methodInst(**params)
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\__init__.py", line 543, in createDeck
    self.startEditing()
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\__init__.py", line 214, in startEditing
    self.window().requireReset()
  File "aqt.main", line 864, in requireReset
requireReset() is obsolete; please use CollectionOp()
[+] Adding 0 new notes and updating 2627 existing notes
Traceback (most recent call last):
  File "S:\3-Languages\xlsm2csv2anki\anki-csv-importer.py", line 363, in <module>
    main()
  File "S:\3-Languages\xlsm2csv2anki\anki-csv-importer.py", line 351, in main
    send_to_anki_connect(
  File "S:\3-Languages\xlsm2csv2anki\anki-csv-importer.py", line 175, in send_to_anki_connect
    front = n['fields']['Front'].replace('"', '\\"')
            ~~~~~~~~~~~^^^^^^^^^
KeyError: 'Front'

C:\Users\User>taskkill /IM anki.exe /Fs
ERROR: Invalid argument/option - '/Fs'.
Type "TASKKILL /?" for usage.

C:\Users\User>

I don’t understand why the field “Front” should be available on the variable “n”, I have checked the code and don’t seem to understand what this should be referring to and why it is not getting generated when I execute it.

Also, my deck in Anki is currently empty, so I am not sure why it is stating “0 new notes and updating 2627 existing notes”.

I have tried debugging the code by providing the args as manual input, however, I don’t understand the issue.

Does someone know how to make it work?

1 Like