I found it easier to start with a file with at least a wing object in it and then modify that. I work in Jupyter-lab so I run things through one cell at a time so I can check and debug it as I go along. It also helps to keep saving the .vsp3 file as you go and keep opening it in OpenVSP so you can check it's doing what you want. So my code was as below. I've also attached the blankwing file that it loaded by this.
import openvsp as vsp
import csv
#Load blankwing
fname = 'blankwing.vsp3'
vsp.VSPRenew()
vsp.ReadVSPFile((path+fname))
geoms = vsp.FindGeoms()
print(geoms)
#Extend with the required number of sections
wid = geoms[0]
for i in range(2,len(sections)):
vsp.InsertXSec(wid, 1, 12)
vsp.Update()
#Save and open this file to check it worked
fnamenew = 'sectwing.vsp3'
vsp.WriteVSPFile(path+fnamenew)
vsp.VSPRenew()
vsp.ReadVSPFile((path+fnamenew))
geoms = vsp.FindGeoms()
#Set the size of each segment (chord and span
for i in range(len(spans)):
xsec = 'XSec_'+str(i+1)
print(xsec)
b_id = vsp.GetParm(wid, "Span",xsec)
c_id = vsp.GetParm(wid, "Root_Chord",xsec)
print('before',vsp.GetParmVal(b_id),vsp.GetParmVal(c_id))
vsp.SetParmVal(b_id, spans[i])
vsp.Update()
vsp.SetParmVal(c_id, chords[i])
vsp.Update()
print('After',vsp.GetParmVal(b_id),vsp.GetParmVal(c_id))
c_id = vsp.GetParm(wid, "Tip_Chord",xsec)
vsp.SetParmVal(c_id, chords[-1])
#Check this bit worked
fnamenew = 'P7API.vsp3'
vsp.WriteVSPFile(path+fnamenew)
vsp.VSPRenew()
vsp.ReadVSPFile((path+fnamenew))
#Assign aerofoils to each segment
xsec_surf = vsp.GetXSecSurf( wid, 0 )
print(xsec_surf)
for i in range(len(sections)):
xsec = vsp.GetXSec(xsec_surf, i)
fname = path+'sections/sec'+str(i)+'.dat'
print(xsec, fname)
vsp.ReadFileAirfoil(xsec, fname)
vsp.Update()