Import contacts from csv via python-kopano

Hello world,

I want to import contacts into a user folder from a .csv-file via a Python script.

My problem is, that I can create the contact and set some attributes like email or email2, but I can’t set first_name or last_name. The traceback shows:

Traceback (most recent call last):
  File "./kopano-adressen.py", line 67, in <module>
   new = kopano.user('testuser').store.folder('Contacts').create_item(email='testuser@test.com', email2='testuser2@test.de', last_name='Python1')
  File "/usr/lib/python3/dist-packages/kopano/folder.py", line 485, in create_item
    setattr(item, key, val)
AttributeError: can't set attribute

This is the code from my script:

#!/usr/bin/python3

import kopano

server = kopano.Server()

new = kopano.user('testuser').store.folder('Contacts').create_item(email='testuser@test.com', email2='testuser2@test.de', last_name='Python1')

I have consulted the documentation but I guess I am not experienced enough in programming to solve this problem.

1 Like

Hi @constable,

for problems and questions that are not directly related to Univention I would always rather recommend to ask them in the Kopano forum directly, for example in the scripting category.

For the specific use case there is already a script that could be used or that could serve as an easy inspiration. You can find it at https://stash.kopano.io/projects/KSC/repos/core-tools/browse/contacts2csv

1 Like

Thank you very much @fbartels!

That script seems to do what I am looking for.