Discussion:
[python-win32] Python COM server throws 'module' object has no attribute 'VARIANT'
Paul Hemans
2012-08-05 13:13:39 UTC
Permalink
Can someone tell me what is going wrong. The following works on one machine
but not on another.

Here is a COM server implemented in Python:

from win32com.server.exception import COMException
import pythoncom
import sys
import os
from string import Template
import logging
import logging.config

class Connector:
_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
_reg_clsid_ = "{0CE25AEB-1AFA-4DA7-97BD-F93CDBFB376C}"
_reg_desc_ = "Python Test COM Server"
_reg_progid_ = "Compy.Connect"
_public_methods_ = ['Process', 'Status']
_public_attrs_ = []
_readonly_attrs_ = []

def Process(self, what):
pass

def Status(self):
return Template("""
Current Directory: $dir
Installed: $script
PythonPATH: $pyPath
""").substitute(dir = os.getcwd(),
script = os.path.abspath(__file__),
pyPath = sys.path)

if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(Connector)

It registers ok. When it is run it causes the following to occur on the
cc = CreateObject("Compy.Connect")
cc.Status()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\comtypes\client\dynamic.py", line 42, in _
_call__
return self._obj._comobj.Invoke(self._id, *args)
File "C:\Python26\lib\site-packages\comtypes\automation.py", line 717, in Invo
ke
raise COMError(hresult, text, details)
_ctypes.COMError: (-2147352567, 'Exception occurred.', (u"Unexpected Python Erro
r: AttributeError: 'module' object has no attribute 'VARIANT'\n", u'Python COM S
erver Internal Error', None, 0L, -2147467259))
I have installed comtypes 0.6.2. Running Python 2.6.6
Mark Hammond
2012-08-06 01:41:55 UTC
Permalink
I don't quite understand this code. The server is using win32com (ie,
not comtypes), but the client code seems to be using comtypes rather
than win32com (but it's hard to tell as the client code is missing the
imports etc). But at face value it appears one of the machines might
have an older version of comtypes installed.

Mark
Post by Paul Hemans
Can someone tell me what is going wrong. The following works on one
machine but not on another.
|from win32com.server.exceptionimport COMException
import pythoncom
import sys
import os
from string import Template
import logging
import logging.config
_reg_clsctx_= pythoncom.CLSCTX_LOCAL_SERVER
_reg_clsid_= "{0CE25AEB-1AFA-4DA7-97BD-F93CDBFB376C}"
_reg_desc_= "Python Test COM Server"
_reg_progid_= "Compy.Connect"
_public_methods_= ['Process', 'Status']
_public_attrs_= []
_readonly_attrs_= []
pass
return Template("""
Current Directory: $dir
Installed: $script
PythonPATH: $pyPath
""").substitute(dir= os.getcwd(),
script= os.path.abspath(__file__),
pyPath= sys.path)
import win32com.server.register
win32com.server.register.UseCommandLine(Connector)
|
It registers ok. When it is run it causes the following to occur on the
|>>> cc= CreateObject("Compy.Connect")
cc.Status()
File "<stdin>", line1, in <module>
File "C:\Python26\lib\site-packages\comtypes\client\dynamic.py", line42, in _
_call__
return self._obj._comobj.Invoke(self._id, *args)
File "C:\Python26\lib\site-packages\comtypes\automation.py", line717, in Invo
ke
raise COMError(hresult, text, details)
_ctypes.COMError: (-2147352567, 'Exception occurred.', (u"Unexpected Python Erro
r: AttributeError: 'module' object has no attribute 'VARIANT'\n", u'Python COM S
erver Internal Error', None, 0L, -2147467259))
|
I have installed comtypes 0.6.2. Running Python 2.6.6
_______________________________________________
python-win32 mailing list
http://mail.python.org/mailman/listinfo/python-win32
Paul Hemans
2012-08-06 05:58:28 UTC
Permalink
Hi Mark,
Thanks for the response.

Here is what I am using to instantiate the server through python
Post by Paul Hemans
from comtypes.client import CreateObject
cc= CreateObject("Compy.Connect")
cc.Status()
The com server also fails when being accessed from vbscript.
I have verified that both machines have comtypes 0.6.2 loaded.

Win32com works on the same machine that comtypes works
Post by Paul Hemans
import win32com.client
wcc = win32com.client.Dispatch("Compy.Connect")
wcc.Status()
When I run this on the machine that fails with comtypes I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<COMObject Compy.Connect>", line 2, in Status
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Python COM
Server Internal Error', u"Unexpected Python Error: AttributeError: 'module'
object has no attribute 'VARIANT'\n", None, 0, -2147467259), None)

Do you have any suggestions as to what I can test?

Thanks,
Paul
I don't quite understand this code. The server is using win32com (ie, not
comtypes), but the client code seems to be using comtypes rather than
win32com (but it's hard to tell as the client code is missing the imports
etc). But at face value it appears one of the machines might have an older
version of comtypes installed.
Mark
Post by Paul Hemans
Can someone tell me what is going wrong. The following works on one
machine but not on another.
|from win32com.server.**exceptionimport COMException
import pythoncom
import sys
import os
from string import Template
import logging
import logging.config
_reg_clsctx_= pythoncom.CLSCTX_LOCAL_SERVER
_reg_clsid_= "{0CE25AEB-1AFA-4DA7-97BD-**F93CDBFB376C}"
_reg_desc_= "Python Test COM Server"
_reg_progid_= "Compy.Connect"
_public_methods_= ['Process', 'Status']
_public_attrs_= []
_readonly_attrs_= []
pass
return Template("""
Current Directory: $dir
Installed: $script
PythonPATH: $pyPath
""").substitute(dir= os.getcwd(),
script= os.path.abspath(__file__),
pyPath= sys.path)
import win32com.server.register
win32com.server.register.**UseCommandLine(Connector)
|
It registers ok. When it is run it causes the following to occur on the
|>>> cc= CreateObject("Compy.Connect")
cc.Status()
File "<stdin>", line1, in <module>
File "C:\Python26\lib\site-**packages\comtypes\client\**dynamic.py",
line42, in _
_call__
return self._obj._comobj.Invoke(self.**_id, *args)
File "C:\Python26\lib\site-**packages\comtypes\automation.**py",
line717, in Invo
ke
raise COMError(hresult, text, details)
_ctypes.COMError: (-2147352567, 'Exception occurred.', (u"Unexpected Python Erro
r: AttributeError: 'module' object has no attribute 'VARIANT'\n", u'Python COM S
erver Internal Error', None, 0L, -2147467259))
|
I have installed comtypes 0.6.2. Running Python 2.6.6
______________________________**_________________
python-win32 mailing list
http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
______________________________**_________________
python-win32 mailing list
http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
--
Best regards,
Paul Hemans

***@laberg.com.au

LABERG Pty Ltd
(02) 4889 9441

www.laberg.com.au
Mark Hammond
2012-08-06 06:07:18 UTC
Permalink
Post by Paul Hemans
Hi Mark,
Thanks for the response.
Here is what I am using to instantiate the server through python
from comtypes.client import CreateObject
cc= CreateObject("Compy.Connect")
cc.Status()
The com server also fails when being accessed from vbscript.
I have verified that both machines have comtypes 0.6.2 loaded.
Win32com works on the same machine that comtypes works
import win32com.client
wcc = win32com.client.Dispatch("Compy.Connect")
wcc.Status()
File "<stdin>", line 1, in <module>
File "<COMObject Compy.Connect>", line 2, in Status
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Python
'module' object has no attribute 'VARIANT'\n", None, 0, -2147467259), None)
You should be able to register the COM object with "--debug" on the
command-line - the message printed on registration should say "(with
debugging)".

Then, run win32traceutil and you should see the complete traceback from
the server. Note that win32com.client.VARIANT was added quite recently
to pywin32, so if the failing machine has an older version it will fail.

HTH,

Mark
Post by Paul Hemans
Do you have any suggestions as to what I can test?
Thanks,
Paul
I don't quite understand this code. The server is using win32com
(ie, not comtypes), but the client code seems to be using comtypes
rather than win32com (but it's hard to tell as the client code is
missing the imports etc). But at face value it appears one of the
machines might have an older version of comtypes installed.
Mark
Can someone tell me what is going wrong. The following works on one
machine but not on another.
|from win32com.server.__exceptionimport COMException
import pythoncom
import sys
import os
from string import Template
import logging
import logging.config
_reg_clsctx_= pythoncom.CLSCTX_LOCAL_SERVER
_reg_clsid_= "{0CE25AEB-1AFA-4DA7-97BD-__F93CDBFB376C}"
_reg_desc_= "Python Test COM Server"
_reg_progid_= "Compy.Connect"
_public_methods_= ['Process', 'Status']
_public_attrs_= []
_readonly_attrs_= []
pass
return Template("""
Current Directory: $dir
Installed: $script
PythonPATH: $pyPath
""").substitute(dir= os.getcwd(),
script= os.path.abspath(__file__),
pyPath= sys.path)
import win32com.server.register
win32com.server.register.__UseCommandLine(Connector)
|
It registers ok. When it is run it causes the following to occur on the
|>>> cc= CreateObject("Compy.Connect")
cc.Status()
File "<stdin>", line1, in <module>
File
"C:\Python26\lib\site-__packages\comtypes\client\__dynamic.py", line42, in _
_call__
return self._obj._comobj.Invoke(self.___id, *args)
File
"C:\Python26\lib\site-__packages\comtypes\automation.__py",
line717, in Invo
ke
raise COMError(hresult, text, details)
_ctypes.COMError: (-2147352567 <tel:%28-2147352567>, 'Exception
occurred.', (u"Unexpected Python Erro
r: AttributeError: 'module' object has no attribute
'VARIANT'\n", u'Python COM S
erver Internal Error', None, 0L, -2147467259 <tel:2147467259>))
|
I have installed comtypes 0.6.2. Running Python 2.6.6
_________________________________________________
python-win32 mailing list
http://mail.python.org/__mailman/listinfo/python-win32
<http://mail.python.org/mailman/listinfo/python-win32>
_________________________________________________
python-win32 mailing list
http://mail.python.org/__mailman/listinfo/python-win32
<http://mail.python.org/mailman/listinfo/python-win32>
--
Best regards,
Paul Hemans
LABERG Pty Ltd
(02) 4889 9441
www.laberg.com.au <http://www.laberg.com.au/>
Paul Hemans
2012-08-06 06:28:33 UTC
Permalink
Hi Mark,
Installed pywin32-217.win32-py2.6.exe and then the problem was resolved.

Thanks again.
Post by Paul Hemans
Hi Mark,
Thanks for the response.
Here is what I am using to instantiate the server through python
Post by Mark Hammond
Post by Paul Hemans
from comtypes.client import CreateObject
cc= CreateObject("Compy.Connect")
cc.Status()
The com server also fails when being accessed from vbscript.
I have verified that both machines have comtypes 0.6.2 loaded.
Win32com works on the same machine that comtypes works
Post by Mark Hammond
Post by Paul Hemans
import win32com.client
wcc = win32com.client.Dispatch("Compy.Connect")
wcc.Status()
File "<stdin>", line 1, in <module>
File "<COMObject Compy.Connect>", line 2, in Status
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Python
'module' object has no attribute 'VARIANT'\n", None, 0, -2147467259),
None)
Do you have any suggestions as to what I can test?
Thanks,
Paul
Post by Mark Hammond
I don't quite understand this code. The server is using win32com (ie,
not comtypes), but the client code seems to be using comtypes rather than
win32com (but it's hard to tell as the client code is missing the imports
etc). But at face value it appears one of the machines might have an older
version of comtypes installed.
Mark
Post by Paul Hemans
Can someone tell me what is going wrong. The following works on one
machine but not on another.
|from win32com.server.**exceptionimport COMException
import pythoncom
import sys
import os
from string import Template
import logging
import logging.config
_reg_clsctx_= pythoncom.CLSCTX_LOCAL_SERVER
_reg_clsid_= "{0CE25AEB-1AFA-4DA7-97BD-**F93CDBFB376C}"
_reg_desc_= "Python Test COM Server"
_reg_progid_= "Compy.Connect"
_public_methods_= ['Process', 'Status']
_public_attrs_= []
_readonly_attrs_= []
pass
return Template("""
Current Directory: $dir
Installed: $script
PythonPATH: $pyPath
""").substitute(dir= os.getcwd(),
script= os.path.abspath(__file__),
pyPath= sys.path)
import win32com.server.register
win32com.server.register.**UseCommandLine(Connector)
|
It registers ok. When it is run it causes the following to occur on the
|>>> cc= CreateObject("Compy.Connect")
cc.Status()
File "<stdin>", line1, in <module>
File "C:\Python26\lib\site-**packages\comtypes\client\**dynamic.py",
line42, in _
_call__
return self._obj._comobj.Invoke(self.**_id, *args)
File "C:\Python26\lib\site-**packages\comtypes\automation.**py",
line717, in Invo
ke
raise COMError(hresult, text, details)
_ctypes.COMError: (-2147352567, 'Exception occurred.', (u"Unexpected Python Erro
r: AttributeError: 'module' object has no attribute 'VARIANT'\n", u'Python COM S
erver Internal Error', None, 0L, -2147467259))
|
I have installed comtypes 0.6.2. Running Python 2.6.6
______________________________**_________________
python-win32 mailing list
http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
______________________________**_________________
python-win32 mailing list
http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
--
Best regards,
Paul Hemans
LABERG Pty Ltd
(02) 4889 9441
www.laberg.com.au
--
Best regards,
Paul Hemans

***@laberg.com.au

LABERG Pty Ltd
(02) 4889 9441

www.laberg.com.au
Loading...