Python COM服务器throws'module'对象没有属性'VARIANT' [英] Python COM server throws 'module' object has no attribute 'VARIANT'

查看:760
本文介绍了Python COM服务器throws'module'对象没有属性'VARIANT'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是以Python实现的COM服务器:

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)

它注册ok。
当它运行时,它会导致生产机器上但不在开发盒上发生以下情况:

It registers ok. When it is run it causes the following to occur on the production machine but NOT on the development box:

>>> 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))
>>>

我安装了comtypes 0.6.2。运行Python 2.6.6

I have installed comtypes 0.6.2. Running Python 2.6.6

推荐答案

VARIANT类是在Pywin32 build 217中引入的。
尝试安装最新版本该机器
它失败。

The VARIANT class was introduced in Pywin32 build 217. Try installing the latest version on the machine that it's failing on.

这篇关于Python COM服务器throws'module'对象没有属性'VARIANT'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆