2013-08-23 37 views
5

Tôi nhận được lỗi sau:python XMPP lỗi đơn giản khách hàng

AttributeError: Client instance has no attribute 'Dispatcher' 

khi chạy đoạn mã sau vào 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) 

sẽ được hạnh phúc nếu ai đó biết làm thế nào để sửa chữa nó.

P.S. Full traceback của lỗi sau khi việc sửa chữa bằng N3RO đề xuất:

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' 

Trước khi sửa chữa:

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

Vui lòng bao gồm truy xuất * đầy đủ * cho lỗi. –

+0

@Martijn Pieters. Tôi đã làm. – user1264304

+1

AttributeError dường như là sự cố xảy ra * sau * kết nối không thành công do hết thời gian chờ. Bạn có đằng sau tường lửa không? –

Trả lời

3

Bạn cần phải xác định một máy chủ mà bạn muốn kết nối đến.

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

Sau khi thay đổi điều này, tôi không thể tạo lại AttributeError.

Tôi cũng khuyên bạn nên sử dụng đúng JID để kiểm tra mã của bạn. Các JID giống như các E-mail được phân cách bởi một @, đó là lý do tại sao trong mã mẫu của bạn jid.getNode() không trả về gì cả.

* Chỉnh sửa dụ Mã của tôi:

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

Cảm ơn. Tôi vẫn gặp lỗi, bạn có thể xem phần truy nguyên đầy đủ trong câu hỏi đã chỉnh sửa của mình. Xin lỗi, tôi đã sửa nó trong câu hỏi. Trên thực tế, tôi có một JID thực trong mã của tôi. – user1264304

+0

Tôi đã thêm mã làm việc vào câu trả lời của mình. Tôi hy vọng rằng có thể giúp bạn. – N3RO

+0

@ N3RO. Cảm ơn, nó làm việc tại nhà của tôi, nhưng không phải ở máy tính kết nối với mạng miền. – user1264304

3

Trong traceback của bạn có vẻ như bạn đang cố gắng để kết nối với talk.gmail.com mà là một miền không còn tồn tại, vì vậy báo cáo kết quả connection.connect sẽ thất bại để mở một kết nối.

Hãy thử kết nối với talk.google.com có thể là tên của máy chủ phù hợp.

Các vấn đề liên quan