代码之家  ›  专栏  ›  技术社区  ›  Alterlife

帕米的麻烦

  •  1
  • Alterlife  · 技术社区  · 15 年前

    我和帕米有点奇怪的问题: http://pamie.sourceforge.net/ .

    我已经编写了一个脚本,根据我在web上找到的recepie进行一些端口(25)转发,下面是重要的代码:

    # forwardc2s(source, destination):    
    #   forwards from client to server.
    #   Tries to post the message to ICE.
    def forwardc2s(source, destination):    
        string = ' '
        message = ''
        while string:
            string = source.recv(1024)
            if string:
    
                if string[:4] == 'DATA' or message <> '':     # Put the entire text of the email into a variable: message
                    message = message + string
    
                destination.sendall(string)
            else:
                posttotracker(message)                            # post message to tracker.
                source.shutdown(socket.SHUT_RD)
                destination.shutdown(socket.SHUT_WR)
    

    “posttotracker”功能尚未完成。。。它包含的全部内容是:

    def posttotracker(message):
        ie = PAMIE('http://google.com/') 
    

    这给了我一个错误,如下所示:

    Unhandled exception in thread started by <function forwardc2s at 0x00E6C0B0>
    Traceback (most recent call last):
      File "main.py", line 2398, in forwardc2s
        posttotracker(message)                            # post message to tracker.
      File "main.py", line 2420, in posttotracker
        ie = PAMIE('http://google.com/')
      File "main.py", line 58, in __init__
        self._ie = win32com.client.dynamic.Dispatch('InternetExplorer.Application')
      File "c:\Python26\lib\site-packages\win32com\client\dynamic.py", line 112, in
    Dispatch
        IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
    
      File "c:\Python26\lib\site-packages\win32com\client\dynamic.py", line 104, in
    _GetGoodDispatchAndUserName
        return (_GetGoodDispatch(IDispatch, clsctx), userName)
      File "c:\Python26\lib\site-packages\win32com\client\dynamic.py", line 84, in _
    GetGoodDispatch
        IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
    D_IDispatch)
    pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, N
    one)
    

    有趣的是,如果我在这个函数之外做了同样的事情(例如在主函数中),库就会完全按照预期工作。

    有什么想法吗?

    1 回复  |  直到 15 年前
        1
  •  1
  •   Alterlife    15 年前

    PAMIE对象在线程内不工作!!!

    我最初是以线程的形式启动forwardc2s。当我把它作为函数调用时,一切都很好!

    请考虑解决这个问题…非常感谢 rubber duck

    推荐文章