[python-win32] PythonCOM produces errors in WSC script

Peteris_Martinsons@exigengroup.lv Peteris_Martinsons@exigengroup.lv
Fri, 7 Feb 2003 10:17:44 +0200


This is a multipart message in MIME format.
--=_alternative 002D91E7C2256CC6_=
Content-Type: text/plain; charset="us-ascii"

Hey all!

Trying to move away  from VBScript to Python. Still I have a problem: 
PythonCOM raises "Not implemented" error if the python code is inside 
*.wsc script.
The same code in *.pys file works fine, and the same code from interactive 
interpreter also without errors.
If the same is written in VBscript, it works without problems.

The *.wsc script is used as a COM object that takes part in a distributed 
transaction, involving MSDTC.
Below are the debug output (DebugView from www.sysinternals.com) and the 
contents of the *.wsc file.

Using win32all 152 on Python 2.2.1, win2000 SP2.

Seems that the difference is in some COM interface that gets used in 
distributed transactions. 

-----------------------------------------------Debug output started 
-----------------------------------------------------
[2020] DoEvent started
[2020] Next line fails
[2020] pythoncom error: Python error invoking COM method.
[2020] Traceback (most recent call last):
[2020]   File "C:\Python22\lib\site-packages\win32com\server\policy.py", 
line 322, in _InvokeEx_
[2020]     return self._invokeex_(dispid, lcid, wFlags, args, kwargs, 
serviceProvider)
[2020]   File "C:\Python22\lib\site-packages\win32com\server\policy.py", 
line 652, in _invokeex_
[2020]     return self._obj_._dynamic_(name, lcid, wFlags, args)
[2020]   File 
"C:\Python22\lib\site-packages\win32comext\axscript\client\scriptdispatch.py", 
line 46, in _dynamic_
[2020]     return self.engine.ApplyInScriptedSection(None, func, 
tuple(realArgs))
[2020]   File 
"C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", 
line 838, in ApplyInScriptedSection
[2020]     self.HandleException(codeBlock)
[2020]   File 
"C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", 
line 925, in HandleException
[2020]     self.scriptSite.OnScriptTerminate(None, result_exception)
[2020] pywintypes.com_error: (-2147467263, 'Not implemented', None, None)
--------------------------------------------Debug output 
end-------------------------------------------------------------

-------------------------------------------WSC script 
start---------------------------------------------------------------
<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
        description="VisiFLOW.EventHandler.Legacy.501"
        progid="VisiFLOW.EventHandler.Legacy.501"
        version="1.00"
        classid="{175A8C1F-6617-4c89-BCC7-80C2F7ACFE26}"
>
</registration>

<public>
        <method name="DoEvent" dispid="1">
                <PARAMETER name="clump"/>
        </method>
</public>

<script language="Python">
<![CDATA[
import win32com.client
import string


def DoEvent(clump):
    #-- object for printing to debug output
    dbg = win32com.client.Dispatch("Scrutil.Debug")
    dbg.Print ("DoEvent started")
 
    #-- clump is a com object that stores key-value pairs, written in C++
    #-- extract keyword parameters from it
    WflID = clump.Value("WORKFLOW_ID")
    PrjID = clump.Value("PROJECT_ID")
    NodeID = clump.Value("NODE_ID")
    ParcelID = clump.Value("PARCEL_ID")
 
 
    #-- create another container for parameters
    clumpParams = win32com.client.Dispatch("VisiFLOW.VO.Clump")
 
    #-- parse unnamed args and store them in com object
    ParamsArray = string.split(clump.Value("PARAMETER"), ",")
    clumpParams.Put("TARGET_MAILBOX", ParamsArray[1])
    clumpParams.Put("TARGET_NODE", ParamsArray[0])
    clumpParams.Put ("ADHOC_TARGET")
 
    #-- create another com object written in C++
    nameParcel = win32com.client.Dispatch("VisiFLOW.VO.Cognomen")
 
    #-- string operations
    strpcog = "//'WORKFLOW/%s/'PARCELS/%s//%s" % (WflID, NodeID, ParcelID)
 
    #-- pass the string to com method
    nameParcel.ParseDisplayName (strpcog)
 
    #-- get another com object using a method call
    wfRO = nameParcel.BindToObject("WorkflowRouter")
 
    dbg.Print ("Next line fails")
    #-- This call fails. Maybe because it receives as parameter another 
com object?
    #-- It has 4 arguments, only the first is not optional.
    narepl = wfRO.PreRouteParcel(nameParcel)
    dbg.Print ("Success")
]]>
</script>

</component>
------------------------------------wsc script 
end--------------------------------------------------------

-------------------- And this goes to debug output some 10-20 minutes 
after last erraneous wsc processing:

[1396] In DllGetClassObject 
[1396] CShellExtClassFactory::CShellExtClassFactory() 
[1396] CShellExtClassFactory::QueryInterface() 
[1396] CShellExtClassFactory::CreateInstance() 
[1396] CShellExt::CShellExt() 
[1396] CShellExt::QueryInterface()==>IID_IShellExtInit 
[1396] CShellExt::AddRef() 
[1396] CShellExt::Initialize() 
[1396] CShellExt::QueryInterface()==>Unknown Interface! 
[1396] CShellExt::QueryInterface()==>Unknown Interface! 
[1396] CShellExt::QueryInterface()==>IID_IContextMenu 
[1396] CShellExt::AddRef() 
[1396] CShellExt::QueryContextMenu() 
[1396] CMF_EXPLORE... 
[1396] CShellExt::AddRef() 
[1396] CShellExt::Release() 
[1396] CShellExt::Release() 
[1396] CShellExt::QueryInterface()==>Unknown Interface! 
[1396] CShellExt::QueryInterface()==>Unknown Interface! 
[1396] CShellExt::Release() 

---------------------------------------end of debug 
output-------------------------------------------------

Regards,
Peteris underscore Martinsons at exigengroup dot lv
--=_alternative 002D91E7C2256CC6_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">Hey all!</font>
<br>
<br><font size=2 face="sans-serif">Trying to move away &nbsp;from VBScript to Python. Still I have a problem: PythonCOM raises &quot;Not implemented&quot; error if the python code is inside *.wsc script.</font>
<br><font size=2 face="sans-serif">The same code in *.pys file works fine, and the same code from interactive interpreter also without errors.</font>
<br><font size=2 face="sans-serif">If the same is written in VBscript, it works without problems.</font>
<br>
<br><font size=2 face="sans-serif">The *.wsc script is used as a COM object that takes part in a distributed transaction, involving MSDTC.</font>
<br><font size=2 face="sans-serif">Below are the debug output (DebugView from www.sysinternals.com) and the contents of the *.wsc file.</font>
<br>
<br><font size=2 face="sans-serif">Using win32all 152 on Python 2.2.1, win2000 SP2.</font>
<br>
<br><font size=2 face="sans-serif">Seems that the difference is in some COM interface that gets used in distributed transactions. </font>
<br>
<br><font size=2 face="sans-serif">-----------------------------------------------Debug output started -----------------------------------------------------</font>
<br><font size=2 face="sans-serif">[2020] DoEvent started</font>
<br><font size=2 face="sans-serif">[2020] Next line fails</font>
<br><font size=2 face="sans-serif">[2020] pythoncom error: Python error invoking COM method.</font>
<br><font size=2 face="sans-serif">[2020] Traceback (most recent call last):</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; File &quot;C:\Python22\lib\site-packages\win32com\server\policy.py&quot;, line 322, in _InvokeEx_</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; &nbsp; return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider)</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; File &quot;C:\Python22\lib\site-packages\win32com\server\policy.py&quot;, line 652, in _invokeex_</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; &nbsp; return self._obj_._dynamic_(name, lcid, wFlags, args)</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; File &quot;C:\Python22\lib\site-packages\win32comext\axscript\client\scriptdispatch.py&quot;, line 46, in _dynamic_</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; &nbsp; return self.engine.ApplyInScriptedSection(None, func, tuple(realArgs))</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; File &quot;C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py&quot;, line 838, in ApplyInScriptedSection</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; &nbsp; self.HandleException(codeBlock)</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; File &quot;C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py&quot;, line 925, in HandleException</font>
<br><font size=2 face="sans-serif">[2020] &nbsp; &nbsp; self.scriptSite.OnScriptTerminate(None, result_exception)</font>
<br><font size=2 face="sans-serif">[2020] pywintypes.com_error: (-2147467263, 'Not implemented', None, None)</font>
<br><font size=2 face="sans-serif">--------------------------------------------Debug output end-------------------------------------------------------------</font>
<br>
<br><font size=2 face="sans-serif">-------------------------------------------WSC script start---------------------------------------------------------------</font>
<br><font size=2 face="sans-serif">&lt;?xml version=&quot;1.0&quot;?&gt;</font>
<br><font size=2 face="sans-serif">&lt;component&gt;</font>
<br><font size=2 face="sans-serif">&lt;?component error=&quot;true&quot; debug=&quot;true&quot;?&gt;</font>
<br><font size=2 face="sans-serif">&lt;registration</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; description=&quot;VisiFLOW.EventHandler.Legacy.501&quot;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; progid=&quot;VisiFLOW.EventHandler.Legacy.501&quot;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; version=&quot;1.00&quot;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; classid=&quot;{175A8C1F-6617-4c89-BCC7-80C2F7ACFE26}&quot;</font>
<br><font size=2 face="sans-serif">&gt;</font>
<br><font size=2 face="sans-serif">&lt;/registration&gt;</font>
<br>
<br><font size=2 face="sans-serif">&lt;public&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &lt;method name=&quot;DoEvent&quot; dispid=&quot;1&quot;&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;PARAMETER name=&quot;clump&quot;/&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/method&gt;</font>
<br><font size=2 face="sans-serif">&lt;/public&gt;</font>
<br>
<br><font size=2 face="sans-serif">&lt;script language=&quot;Python&quot;&gt;</font>
<br><font size=2 face="sans-serif">&lt;![CDATA[</font>
<br><font size=2 face="sans-serif">import win32com.client</font>
<br><font size=2 face="sans-serif">import string</font>
<br>
<br>
<br><font size=2 face="sans-serif">def DoEvent(clump):</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- object for printing to debug output</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; dbg = win32com.client.Dispatch(&quot;Scrutil.Debug&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; dbg.Print (&quot;DoEvent started&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- clump is a com object that stores key-value pairs, written in C++</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- extract keyword parameters from it</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; WflID = clump.Value(&quot;WORKFLOW_ID&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; PrjID = clump.Value(&quot;PROJECT_ID&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; NodeID = clump.Value(&quot;NODE_ID&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; ParcelID = clump.Value(&quot;PARCEL_ID&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- create another container for parameters</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; clumpParams = win32com.client.Dispatch(&quot;VisiFLOW.VO.Clump&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- parse unnamed args and store them in com object</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; ParamsArray = string.split(clump.Value(&quot;PARAMETER&quot;), &quot;,&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; clumpParams.Put(&quot;TARGET_MAILBOX&quot;, ParamsArray[1])</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; clumpParams.Put(&quot;TARGET_NODE&quot;, ParamsArray[0])</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; clumpParams.Put (&quot;ADHOC_TARGET&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- create another com object written in C++</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; nameParcel = win32com.client.Dispatch(&quot;VisiFLOW.VO.Cognomen&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- string operations</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; strpcog = &quot;//'WORKFLOW/%s/'PARCELS/%s//%s&quot; % (WflID, NodeID, ParcelID)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- pass the string to com method</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; nameParcel.ParseDisplayName (strpcog)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- get another com object using a method call</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; wfRO = nameParcel.BindToObject(&quot;WorkflowRouter&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; dbg.Print (&quot;Next line fails&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- This call fails. Maybe because it receives as parameter another com object?</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; #-- It has 4 arguments, only the first is not optional.</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; narepl = wfRO.PreRouteParcel(nameParcel)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; dbg.Print (&quot;Success&quot;)</font>
<br><font size=2 face="sans-serif">]]&gt;</font>
<br><font size=2 face="sans-serif">&lt;/script&gt;</font>
<br>
<br><font size=2 face="sans-serif">&lt;/component&gt;</font>
<br><font size=2 face="sans-serif">------------------------------------wsc script end--------------------------------------------------------</font>
<br>
<br><font size=2 face="sans-serif">-------------------- And this goes to debug output some 10-20 minutes after last erraneous wsc processing:</font>
<br>
<br><font size=2 face="sans-serif">[1396] In DllGetClassObject </font>
<br><font size=2 face="sans-serif">[1396] CShellExtClassFactory::CShellExtClassFactory() </font>
<br><font size=2 face="sans-serif">[1396] CShellExtClassFactory::QueryInterface() </font>
<br><font size=2 face="sans-serif">[1396] CShellExtClassFactory::CreateInstance() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::CShellExt() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryInterface()==&gt;IID_IShellExtInit </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::AddRef() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::Initialize() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryInterface()==&gt;Unknown Interface! </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryInterface()==&gt;Unknown Interface! </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryInterface()==&gt;IID_IContextMenu </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::AddRef() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryContextMenu() </font>
<br><font size=2 face="sans-serif">[1396] CMF_EXPLORE... </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::AddRef() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::Release() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::Release() </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryInterface()==&gt;Unknown Interface! </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::QueryInterface()==&gt;Unknown Interface! </font>
<br><font size=2 face="sans-serif">[1396] CShellExt::Release() </font>
<br>
<br><font size=2 face="sans-serif">---------------------------------------end of debug output-------------------------------------------------</font>
<br>
<br><font size=2 face="sans-serif">Regards,</font>
<br><font size=2 face="sans-serif">Peteris underscore Martinsons at exigengroup dot lv</font>
--=_alternative 002D91E7C2256CC6_=--