PythonCOM in ASP: very dodgy behaviour
Dale Strickland-Clark
dale at riverhall.NOTHANKS.co.uk
Thu Dec 19 13:49:33 EST 2002
This is turning into a bit of a puzzle. I posted about the problem a
while ago but didn't get much response. We really need to sort this
out now.
We are trying to store a Python object in the ASP session object but
it won't play ball. The object retrieved isn't the same as the one
that went in.
I've reduced the problem to two small modules. One ASP/Python, the
other pure Python.
The Python module is a simple object with a COM interface. The ASP
module instantiates the Python object and then tries to wrap it as a
COM object to store in the ASP Session object.
The output and error is:
246 -1- 492
Python ActiveX Scripting Engine error '80020009'
Traceback (most recent call last): File "<Script Block >", line 13, in
? objWibble = unwrap(wrapWibble) File
"C:\Python22\lib\site-packages\win32com\server\util.py", line 36, in
unwrap ob = pythoncom.UnwrapObject(ob) ValueError: argument is not a
COM object
?, line 0
ob = pythoncom.UnwrapObject(ob)
So in summary: what goes into the Session object doesn't seem to come
out again.
Any and all help gratefully received.
Further info: Python 2.2.2 with Win32all 150 (or 148) on Win2K
---- COMHarness.asp ----
<% @Language=Python %>
<%
import COMHarness2
from win32com.server.util import wrap, unwrap
objWibble = COMHarness2.COMWibble() # Get Object
Response.Write(objWibble.Wibble()) # Test object works
Response.Flush() # Flush output
wrapWibble = wrap(objWibble) # wrap object in COM wrapper
objWibble = unwrap(wrapWibble) # unwrap again
Response.Write(" -1- ") # id. output
Response.Write(objWibble.Wibble()) # test unwrapped object
Response.Flush()
Session.SetValue("Wibble", wrapWibble) # store wrapped object in
Session object
wrapWibble = Session("Wibble") # retrieve from session object
objWibble = unwrap(wrapWibble) # unwrap retrieved object
Response.Write(" -2- ") # id. output
Response.Write(objWibble.Wibble()) # test unwrapped object.
Response.Flush()
%>
----------END-----------
---- COMHarness2.py ----
class COMWibble:
_public_methods_ = ['Wibble']
_public_attrs_ = ['Wobble']
_reg_progid_ = 'Wibble.Test.1'
_reg_clsid_ = '{E871E6D2-BCBF-45E3-AF4A-791A7E153070}'
def __init__(self):
self.Wobble = 123
def Wibble(self):
self.Wobble *= 2
return self.Wobble
def Wobble(self):
return self.Wobble
_value_ = Wobble
if __name__ == '__main__':
print "Registering COM server..."
import win32com.server.register as reg
reg.UseCommandLine(COMWibble)
----------END-----------
--
Dale Strickland-Clark
Riverhall Systems Ltd
More information about the Python-list
mailing list