Jajcus/pyxmpp2 — Issue #68: connection error with GTALK
Author: demonlj
Created: 2011-12-19 13:00:27+00:00
State: open

I followed the document to modified the simple client example like this, but i can only get ERROR!
system: UBUNTU 11.10 / TOMATO WRT
python: 2.7.2

=========================================MODIFIED SCRIPT===============================
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
A simple client example.

The script asks for a sender JID and password, target JID and a message.
Then, it connects to the sender's server and sends the message to the target
JID.
"""

import sys
import logging
from getpass import getpass

from pyxmpp2.jid import JID
from pyxmpp2.message import Message
from pyxmpp2.client import Client
from pyxmpp2.settings import XMPPSettings
from pyxmpp2.interfaces import EventHandler, event_handler, QUIT
from pyxmpp2.streamevents import AuthorizedEvent, DisconnectedEvent

class MyHandler(EventHandler):
def __init__(self, target_jid, message):
self.target_jid = target_jid
self.message = message

@event_handler(AuthorizedEvent)
def handle_authorized(self, event):
message = Message(to_jid = self.target_jid, body = self.message)
event.stream.send(message)
event.stream.disconnect()

@event_handler(DisconnectedEvent)
def handle_disconnected(self, event):
return QUIT

@event_handler()
def handle_all(self, event):
logging.info(u"-- {0}".format(event))

logging.basicConfig(level = logging.DEBUG) # change to 'DEBUG' to see more

your_jid = 'GTALK1@gmail.com'
your_password = 'MY PASSWORD'
target_jid = 'GTALK2@gmail.com'
message = 'is a message'

handler = MyHandler(JID(target_jid), message)
settings = XMPPSettings({
u"password": your_password,
u"starttls": True,
u"tls_verify_peer": False,
u"server":'talk.google.com',
u"c2s_port":5223,
})
client = Client(JID(your_jid), [handler], settings)
client.connect()
client.run()
=================================ERROR MESSAGE==========================
DEBUG:pyxmpp2.transport: _set_state('resolve-hostname')
DEBUG:pyxmpp2.mainloop.events: dispatching...
DEBUG:pyxmpp2.mainloop.events: queue empty
DEBUG:pyxmpp2.mainloop.poll: preparing handler:
DEBUG:pyxmpp2.transport:TCPTransport.prepare(): state: 'resolve-hostname'
DEBUG:pyxmpp2.transport: _set_state('resolving-hostname')
DEBUG:pyxmpp2.transport:_dst_nameports: [('talk.google.com', 5223)]
DEBUG:pyxmpp2.transport: _set_state('connect')
DEBUG:pyxmpp2.transport:TCP transport event: Resolving address of 'talk.google.com'...
DEBUG:pyxmpp2.transport:TCPTransport.prepare(): new state: 'connect'
DEBUG:pyxmpp2.mainloop.poll: prepare result: PrepareAgain(0)
DEBUG:pyxmpp2.mainloop.events: dispatching...
DEBUG:pyxmpp2.mainloop.events: event:
DEBUG:pyxmpp2.mainloop.events: handlers: [(1, >)]
DEBUG:pyxmpp2.mainloop.events: passing the event to: >
INFO:root:-- Resolving address of 'talk.google.com'...
DEBUG:pyxmpp2.mainloop.events: dispatching...
DEBUG:pyxmpp2.mainloop.events: queue empty
DEBUG:pyxmpp2.mainloop.poll: preparing handler:
DEBUG:pyxmpp2.transport:TCPTransport.prepare(): state: 'connect'
DEBUG:pyxmpp2.transport:Connect error: [Errno 101] Network is unreachable
DEBUG:pyxmpp2.transport: _set_state('connect')
DEBUG:pyxmpp2.transport:TCPTransport.prepare(): new state: 'connect'
DEBUG:pyxmpp2.mainloop.poll: prepare result: PrepareAgain()
DEBUG:pyxmpp2.mainloop.events: dispatching...
DEBUG:pyxmpp2.mainloop.events: queue empty
DEBUG:pyxmpp2.mainloop.poll: preparing handler:
DEBUG:pyxmpp2.transport:TCPTransport.prepare(): state: 'connect'
DEBUG:pyxmpp2.transport:Connect error: [Errno 115] Operation now in progress
DEBUG:pyxmpp2.transport: _set_state('connecting')
DEBUG:pyxmpp2.transport:TCP transport event: Connecting to 74.125.71.125:5223...
DEBUG:pyxmpp2.transport:TCPTransport.prepare(): new state: 'connecting'
DEBUG:pyxmpp2.mainloop.poll: prepare result: PrepareAgain()
Traceback (most recent call last):
File "send_message_client.py", line 59, in
client.run()
File "/usr/local/lib/python2.7/dist-packages/pyxmpp2-2.0alpha2_git-py2.7.egg/pyxmpp2/client.py", line 216, in run
self.main_loop.loop(timeout)
File "/usr/local/lib/python2.7/dist-packages/pyxmpp2-2.0alpha2_git-py2.7.egg/pyxmpp2/mainloop/base.py", line 86, in loop
self.loop_iteration(interval)
File "/usr/local/lib/python2.7/dist-packages/pyxmpp2-2.0alpha2_git-py2.7.egg/pyxmpp2/mainloop/poll.py", line 131, in loop_iteration
self._configure_io_handler(handler)
File "/usr/local/lib/python2.7/dist-packages/pyxmpp2-2.0alpha2_git-py2.7.egg/pyxmpp2/mainloop/poll.py", line 66, in _configure_io_handler
self.poll.unregister(old_fileno)
KeyError: 3