Hi,
I've got an python app that I'm trying to access the iTunes com API with,
and this app runs as a Windows service. When I run it I get these
GetGoodDispatchAndUserName errors. I think it ends up being related to the
service not having security access to the Com interface? I've tried setting
the --username --password params when I start the service like so:
python MyService.py --username abc --password xyz start
The instance's SvcRun() method failed
File "C:\Python26\Lib\site-packages\win32\lib\win32serviceutil.py", line
805, in SvcRun
self.SvcDoRun()
File "C:\MyService\MyService.py", line 54, in SvcDoRun
itnes = win32com.client.Dispatch("iTunes.Application")
File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 95,
in Dispatch
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 98,
in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 78,
in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
<class 'pywintypes.com_error'>: (-2146959355, 'Server execution failed',
None, None)
Here is the slimmed down source code:
import win32com.client
import win32serviceutil
import win32service
import time
import win32event
import win32evtlogutil
import win32api
import win32traceutil
import servicemanager
logger = file("C:\log.txt","a+")
def log(txt):
txt = txt+"\n"
logger.write(txt)
log("\n\nService attempting to start")
logger.flush()
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = "MyService"
_svc_display_name_ = "MyService"
def __init__(self, args):
log("in _init_")
logger.flush()
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
log("in _stop")
logger.flush()
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
logger.close()
def SvcDoRun(self):
log("in _start")
itnes = win32com.client.Dispatch("iTunes.Application")
log("numTracks: ")
logger.flush()
# wait for beeing stopped...
while 1:
res = win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
if res == win32event.WAIT_OBJECT_0:
break # Must be terminating
log("in _start waiting")
logger.flush()
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyService)
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32