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

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\", line 93, in advance
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 136, in advance
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 151, in advanceClients
    self.clients = list(filter(lambda c: c.advance(), self.clients))
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 151, in <lambda>
    self.clients = list(filter(lambda c: c.advance(), self.clients))
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 68, in advance
    self.writeBuff += self.handler(req)
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 202, in handlerWrapper
    body = json.dumps(self.handler(params)).encode('utf-8')
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 130, in handler
    api_return_value = methodInst(**params)
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 543, in createDeck
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\2055492159\", line 214, in startEditing
  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\", line 363, in <module>
  File "S:\3-Languages\xlsm2csv2anki\", line 351, in main
  File "S:\3-Languages\xlsm2csv2anki\", 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.


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