fritzy / SleekXMPP

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

issue with python3, dnspython and IPv6 #422

Open paalbra opened 8 years ago

paalbra commented 8 years ago

There seems to be an issue if you use python3 with dnspython and the host resolves to IPv6.

Looks like the resolved address is a bytes-like object and not the expected str.

Installed with pip3: dnspython (1.14.0) sleekxmpp (1.3.1)

Python version: 3.5.1

The line numbers of my 1.3.1 install does not seem to match the sleek-1.3.1 tag. I don't know why this is the case.

Traceback (most recent call last):
  File "mybot.py", line 81, in <module>
    if xmpp.connect():
  File "/usr/lib/python3.5/site-packages/sleekxmpp/clientxmpp.py", line 160, in connect
    reattempt=reattempt)
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 448, in connect
    args=(reattempt,))
  File "/usr/lib/python3.5/site-packages/sleekxmpp/thirdparty/statemachine.py", line 70, in transition
    func=func, args=args, kwargs=kwargs)
  File "/usr/lib/python3.5/site-packages/sleekxmpp/thirdparty/statemachine.py", line 111, in transition_any
    return_val = func(*args,**kwargs) if func is not None else True
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 496, in _connect
    if ':' in self.address[0]:
TypeError: a bytes-like object is required, not 'str'

I hope this issue report is OK. My first report ever on github.

jdiemz commented 8 years ago

I'm having the same issue, except with ipv4. Using the same versions of dnspython and sleekxmpp.

[2016-08-30 21:39:18,242] DEBUG [resolver.get_SRV()] DNS: Querying SRV records for mydomain.com
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap
    self.run()
  File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/jdiemz/projects/pro/pro/xmpp/__init__.py", line 79, in worker
    if xmpp.connect():
  File "/usr/lib/python3.5/site-packages/sleekxmpp/clientxmpp.py", line 160, in connect
    reattempt=reattempt)
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 448, in connect
    args=(reattempt,))
  File "/usr/lib/python3.5/site-packages/sleekxmpp/thirdparty/statemachine.py", line 70, in transition
    func=func, args=args, kwargs=kwargs)
  File "/usr/lib/python3.5/site-packages/sleekxmpp/thirdparty/statemachine.py", line 111, in transition_any
    return_val = func(*args,**kwargs) if func is not None else True
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 484, in _connect
    self.address[1])
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 1107, in pick_dns_answer
    return next(self.dns_answers)
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/resolver.py", line 138, in resolve
    use_dnspython=use_dnspython)
  File "/usr/lib/python3.5/site-packages/sleekxmpp/xmlstream/resolver.py", line 331, in get_SRV
    if host.endswith('.'):
TypeError: endswith first arg must be bytes or a tuple of bytes, not str

Looks like rec.target.to_text() is returning a byte-string instead of a normal string.

XRevan86 commented 8 years ago

Duplicate of #416. At least I think it is. Anyway, #418 is for this exact issue.

jdiemz commented 8 years ago

Yup, I think you're right. And your patch fixes my issue, thanks.