'I am getting following "Error : A tree takes one root merely" when tried to display tree structure using treelib & pyodbc in python

import pyodbc
from treelib import Node, Tree


try:
    tree  = Tree()
    tree1 = Tree()

    tree1.create_node("Gopalakrishnan","Gopalakrishnan")
    tree1.create_node("Vadivel", "Vadivel", parent="Gopalakrishnan")
    tree1.show()

# tree1 is working fine., below logic for tree2 is not working as expected.

    cnxn = pyodbc.connect("DSN=**;database=*;trusted_connection=yes;user=**;password=**")
    cursor = cnxn.cursor()
    cursor.execute("select distinct Sno, TreeLibCode from dbo.TreeLibTable")
    rows=cursor.fetchall()
    for row in rows:
        #tree.create_node(eval(row[1])) #eval is also not working.
        tree.create_node(row[1])
    tree.show()

except Exception as e:
    print("Error : ",e)

finally:
        cursor.close()
        cnxn.close()

result from select query:

|1 |"Gopalakrishnan", "Gopalakrishnan"

|2 |"Vadivel","Vadivel", parent="Gopalakrishnan"

output :

Gopalakrishnan

└── Vadivel

Error : A tree takes one root merely.

Output of Tree1 is fine, but Tree2 is throwing above error. Please help me in get this issue resolved.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source