fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

Getting index error #164

Closed akhilpo closed 9 years ago

akhilpo commented 12 years ago

When running as a client for facebook get, I am getting the following error occationally:

Error reading from XML stream.
no element found: line 1, column 108341
Traceback (most recent call last):
  File "<string>", line 82, in __next__
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python32\lib\site-packages\sleekxmpp\xmlstream\xmlstream.py", line 1150, in _process
    if not self.__read_xml():
  File "C:\Python32\lib\site-packages\sleekxmpp\xmlstream\xmlstream.py", line 1186, in __read_xml
    for event, xml in ET.iterparse(self.filesocket, (b'end', b'start')):
  File "<string>", line 96, in __next__
  File "<string>", line None
cElementTree.ParseError: no element found: line 1, column 108341

What's wrong here??

My code:

import sleekxmpp
import logging

def session_start(event):
    chatbot.send_presence()
    print('Session started')
    chatbot.get_roster()

def message(msg):
    if msg['type'] in ('chat','normal'):
        print("msg recieved")
        print(msg['body'])

        msg.reply("Thanks").send()

jid = 'some id@chat.facebook.com'
password = 'somepassword'
addr = ('chat.facebook.com', 5222)
ipaddr = ('209.85.175.125',5222)

chatbot = sleekxmpp.ClientXMPP(jid,password)
chatbot.add_event_handler("session_start", session_start)
chatbot.add_event_handler("message", message)

chatbot.auto_reconnect = True

chatbot.connect(addr)
chatbot.process(block=True)
legastero commented 12 years ago

It looks like you are using the 1.0 release, right?

That error means that the connection was cut. Looking at the Facebook XMPP group, it appears that Facebook is having issues with dropping clients today, which would be the cause of this issue.

If you use the develop branch, this error is handled properly (it is caught and handled in 1.0, it just also logs the exception trace).

akhilpo commented 12 years ago

thanks..

akhilpo commented 12 years ago

I updated the package to the develop version and hit with another issue.

Traceback (most recent call last):
  File "D:\Work folder\Python\sleekxmppyproj32.py", line 32, in <module>
    chatbot.connect(addr)
  File "C:\Python32\lib\site-packages\sleekxmpp\clientxmpp.py", line 154, in connect
    reattempt=reattempt)
  File "C:\Python32\lib\site-packages\sleekxmpp\xmlstream\xmlstream.py", line 417, in connect
    func=self._connect, args=(reattempt,))
  File "C:\Python32\lib\site-packages\sleekxmpp\thirdparty\statemachine.py", line 69, in transition
    func=func, args=args, kwargs=kwargs)
  File "C:\Python32\lib\site-packages\sleekxmpp\thirdparty\statemachine.py", line 107, in transition_any
    return_val = func(*args,**kwargs) if func is not None else True
  File "C:\Python32\lib\site-packages\sleekxmpp\xmlstream\xmlstream.py", line 454, in _connect
    self.address[1])
  File "C:\Python32\lib\site-packages\sleekxmpp\xmlstream\xmlstream.py", line 947, in pick_dns_answer
    return next(self.dns_answers)
  File "C:\Python32\lib\site-packages\sleekxmpp\xmlstream\resolver.py", line 96, in resolve
    ipv4 = socket.inet_pton(socket.AF_INET, host)
AttributeError: 'module' object has no attribute 'inet_pton'

Now it doesnt even connect.. :(

akhilpo commented 12 years ago

Reverted back to Master (v1.0) and it works fine. At least it connects and runs now.

Is that "socket..inet_pton()" supposed to be "socket.inet_aton()"?? :/ just a wild guess....

legastero commented 12 years ago

Ah, Windows. Looks like its socket module doesn't have inet_pton. One sec and I'll patch things to now use that method unless its available.

legastero commented 12 years ago

Ok, develop is updated to not use inet_pton unless its available. This may mean that specifying an IPv6 literal as the server name on a Windows machine may potentially behave oddly.

legastero commented 12 years ago
Is that "socket..inet_pton()" supposed to be "socket.inet_aton()"?? :/

socket.inet_aton only handles IPv4 literals. To handle IPv4 and IPv6 requires inet_pton.

akhilpo commented 12 years ago

Is there any better solution that handles both? I will try the new one.

bear commented 9 years ago

@0xakhil I'm going to mark this as closed - the issue and version are old enough that if this is still happening it would be saner to have a new issue after seeing if it exists in the latest SleekXMPP