首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >帕米的麻烦

帕米的麻烦
EN

Stack Overflow用户
提问于 2009-06-15 05:48:52
回答 1查看 790关注 0票数 1

我和http://pamie.sourceforge.net/遇到了一些奇怪的问题。

我已经写了一个脚本,根据我在web上找到的一个接收器来做一些端口(25)转发,下面是重要的代码:

代码语言:javascript
复制
# 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”函数尚未完成...它所包含的全部内容是:

代码语言:javascript
复制
def posttotracker(message):
    ie = PAMIE('http://google.com/') 

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

代码语言:javascript
复制
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)

有趣的是,如果我在此函数之外(例如,在main函数中)执行完全相同的操作,库将完全按照预期工作。

有什么想法吗?

如果这些信息还不够充分,请原谅我,我只是一个初级的python程序员。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-06-15 06:18:27

PAMIE对象不能在线程中工作!

我最初是作为一个线程启动forwardc2s的。当我只是将它作为一个函数调用时,一切都很正常!

请认为此问题已解决...非常感谢rubber duck

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/994627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档