I have seen the included Powershell code, but how to use the API from Python?
Good timing - just a few days ago we added a Python SeeShell API demo project to GitHub:
from win32com import client # needed for connecting to COM
import csv #built in python lib for reading csv file
import sys
#SeeShell API - Python Demo Script
#Screencast on Youtube: https://www.youtube.com/watch?v=jlgJQwzEVp4
#This is script is the Python version of "Submit-CSV.VBS".
#It reads a CSV file line by line, and uses SeeShell Browser
#to submit the data to a website.
# the filename of the csv containing name and email
INPUT_FILE = 'namesandemail.csv'
# display message in console and wait for enter key
print("Press Enter to start CSV submission")
sys.stdin.readline()
# activate SeeShell COM objects
objB = client.Dispatch("SeeShell.Browser")
objB.open(10)
with open(INPUT_FILE, 'rt') as fp: # open the csv file containing name and email
reader = csv.reader(fp) # load it to CSV reader
for row in reader: # for each row
i = objB.echo("Processing Name: {} {}".format(row[0], row[0]))
i = objB.setVariable("first", row[0])
i = objB.setVariable("last", row[1])
i = objB.setVariable("email", row[2])
i = objB.play("Demo-Variables")
if i < 0:
print("Play error: %d" % (i,) + " " + objB.getLastError())
print("Done, press Enter to close the SeeShell Browser")
sys.stdin.readline()
objB.close()
I am seeing following error, while executing above script.
Press Enter to start CSV submission
Traceback (most recent call last):
File "submit_csv.py", line 20, in <module>
objB = client.Dispatch("SeeShell.Browser")
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
I see you are using Python 2.7, but the script was created and tested with the latest Python version: Python 3.7