遇到pamie问题
我在使用pamie的时候遇到了一些奇怪的问题:http://pamie.sourceforge.net/。
我写了一个脚本,用于进行端口(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)
有趣的是,如果我在这个函数外面(比如在主函数里)做同样的事情,这个库就能正常工作。
有没有什么想法?
如果这些信息不够,请原谅,我只是一个刚开始学习Python的编程新手。
1 个回答
1
PAMIE对象在线程中无法使用!!!
我最开始是把forwardc2s当作一个线程来启动的。但是当我直接把它当作一个函数来调用时,一切都正常了!
请把这个问题看作已经解决了... 非常感谢橡皮鸭的帮助。