2009-06-15 13 views
1

私は、パミにいくつか変なトラブルがあります:http://pamie.sourceforge.net/です。私はウェブ上で発見recepieに基づいて、いくつかのポート(25)転送を行うためのスクリプトを書かれているpamieとのトラブル

が、ここで重要なコードは次のとおりです。

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

面白いのは、私がこの関数の外で(例えばmain関数で)まったく同じことをすると、ライブラリは期待どおりに正確に動作するということです。

アイデア?

この情報が不十分な場合は、私はちょうど出発点のパイソンコーダーです。

答えて

1

スレッド内でPAMIEオブジェクトが機能しません。

私はもともとスレッドとしてforwardc2sを開始しました。代わりに関数として呼び出すと、すべて正常に動作します。

rubber duckに感謝してこの問題を解決してください。

+0

私はこの30秒よりもずっと長い時間を要していただろう=) – Claudiu

+0

今、それは2012年で、私はこの質問をもう一度見つけて、この回答が役に立ったと気づいた。コメントも。素晴らしいもの。 – Claudiu