2013-08-23 35 views
5

,我發現了以下錯誤:蟒蛇XMPP簡單的客戶端錯誤

AttributeError: Client instance has no attribute 'Dispatcher' 

而在Python 2.7運行下面的代碼:

import xmpp 

user= '[email protected]' 
password="pass" 

jid = xmpp.JID(user) 
connection = xmpp.Client(jid.getDomain()) 
connection.connect() 
connection.auth(jid.getNode(),password) 

會很高興,如果有人知道如何解決它。

P.S.通過N3RO提出的修正後的誤差全部追蹤:

C:\Users\krasnovi\Desktop\temp\xmpp tests>python xmpp.client.py 
Invalid debugflag given: always 
Invalid debugflag given: nodebuilder 
DEBUG: 
DEBUG: Debug created for build\bdist.win-amd64\egg\xmpp\client.py 
DEBUG: flags defined: always,nodebuilder 
DEBUG: socket  start Plugging <xmpp.transports.TCPsocket instance at 0x0000 
0000027C1708> into <xmpp.client.Client instance at 0x00000000027C1588> 
DEBUG: socket  warn An error occurred while looking up _xmpp-client._tcp.t 
alk.gmail.com 
DEBUG: socket  error Failed to connect to remote host ('talk.gmail.com', 52 
23): getaddrinfo failed (11004) 
Traceback (most recent call last): 
    File "build\bdist.win-amd64\egg\xmpp\transports.py", line 133, in connect 
    self._sock.connect((server[0], int(server[1]))) 
    File "C:\Python27\lib\socket.py", line 224, in meth 
    return getattr(self._sock,name)(*args) 
gaierror: [Errno 11004] getaddrinfo failed 
DEBUG: socket  stop Plugging <xmpp.transports.TCPsocket instance at 0x0000 
0000027C1708> out of <xmpp.client.Client instance at 0x00000000027C1588>. 
Traceback (most recent call last): 
    File "xmpp.client.py", line 11, in <module> 
    connection.auth(jid.getNode(),password) 
    File "build\bdist.win-amd64\egg\xmpp\client.py", line 214, in auth 
AttributeError: Client instance has no attribute 'Dispatcher' 

修復前:

Invalid debugflag given: always 
Invalid debugflag given: nodebuilder 
DEBUG: 
DEBUG: Debug created for build\bdist.win-amd64\egg\xmpp\client.py 
DEBUG: flags defined: always,nodebuilder 
DEBUG: socket  start Plugging <xmpp.transports.TCPsocket instance at 0x0000 
0000027ED708> into <xmpp.client.Client instance at 0x00000000027ED588> 
DEBUG: socket  error Failed to connect to remote host ('xmpp.l.google.com.' 
, 5222): A connection attempt failed because the connected party did not properl 
y respond after a period of time, or established connection failed because conne 
cted host has failed to respond (10060) 
Traceback (most recent call last): 
    File "build\bdist.win-amd64\egg\xmpp\transports.py", line 133, in connect 
    self._sock.connect((server[0], int(server[1]))) 
    File "C:\Python27\lib\socket.py", line 224, in meth 
    return getattr(self._sock,name)(*args) 
error: [Errno 10060] A connection attempt failed because the connected party did 
not properly respond after a period of time, or established connection failed b 
ecause connected host has failed to respond 
DEBUG: socket  stop Plugging <xmpp.transports.TCPsocket instance at 0x0000 
0000027ED708> out of <xmpp.client.Client instance at 0x00000000027ED588>. 
Traceback (most recent call last): 
    File "xmpp.client.py", line 11, in <module> 
    connection.auth(jid.getNode(),password) 
    File "build\bdist.win-amd64\egg\xmpp\client.py", line 214, in auth 
AttributeError: Client instance has no attribute 'Dispatcher' 
+0

請包括錯誤的* full *回溯。 –

+0

@Martijn Pieters。我做到了。 – user1264304

+1

AttributeError似乎是由於超時而導致連接失敗後發生的問題。你是否在防火牆後面? –

回答

3

您需要指定要連接到服務器。

connection.connect(server=('serveradress.com', portnumber)) 

更改後,我無法再現AttributeError。

我還建議你使用正確的JID來測試你的代碼。JID就像由@分隔的電子郵件,這就是爲什麼在您的示例代碼中,jid.getNode()不返回任何內容。

*編輯我的代碼,例如:

import xmpp 

user = '[email protected]' 
password = 'password' 

jid = xmpp.JID(user) 

connection = xmpp.Client(jid.getDomain()) 
connection.connect(server=('talk.google.com', 5223)) 
connection.auth(jid.getNode(), password) 
connection.sendInitPresence() 
+0

謝謝。我仍然收到錯誤,你可以在我編輯的問題中看到完整的回溯。對不起,我已經修復了這個問題。其實,我的代碼中確實有一個真正的JID。 – user1264304

+0

我將我的工作代碼添加到我的答案中。我希望能幫助你。 – N3RO

+0

@ N3RO。謝謝,它在我的家中工作,但不在連接到域網絡的計算機上。 – user1264304

3

在你回溯它看起來像你試圖連接到talk.gmail.com這是一個不存在的域,所以connection.connect聲明將無法打開連接。

嘗試連接到talk.google.com這可能是正確的服務器名稱。