Project.connect_ontology(ontology) throws StopIteration

Hi there, I am trying to link ontology to my project:

project = client.get_projects(
        where=lb.Project.name == args.project_name).get_one()
print(project)
ontology = next(client.get_ontologies(args.ontology_name))
print(ontology)
project.connect_ontology(ontology)

The last line (connect_ontology) raises a StopIteration exception.
However, I can log in to the web interface, and connect that project to that ontology manually via clicking buttons.
What am I doing wrong in the python sdk?
Thanks!

if you have an ontology already connected to your project this will fail:

ValueError: Ontology already connected to project.

This was implemented to avoid corrupting projects that already has labels.