python-cymru-services icon indicating copy to clipboard operation
python-cymru-services copied to clipboard

cymru/core/dns.py bytes/unicode error interfacing with ipaddress

Open dogwynn opened this issue 11 years ago • 3 comments

Greetings, I tried running the example code in the README for cymru-services, and I kept running into an issue with the line "client.lookup(ip,qType='IP')" giving me an AddressValueError from the ipaddress module. It ended up being a problem in cymru/core/dns.py

Below is the patch to fix:

--- cymru/core/dns.py   2014-08-20 15:39:39.000000000 -0400
+++ cymru.delta/core/dns.py 2014-08-20 15:40:18.000000000 -0400
@@ -51,7 +51,7 @@
     # clean values and type IP values
     if qType is None:
       qType=self.QTYPES[0]
-    values = [str(value).strip() for value in values]
+    values = [unicode(value).strip() for value in values]
     log.debug("values :%s" % (values)) 
     if qType in ['IP','IP6']:
       values = [ip_expand(value) for value in values]

dogwynn avatar Aug 20 '14 19:08 dogwynn

Can you share your test case, python version, IPy version (or not) ipaddress version ?

unicode is not a supported python3 keyword from what I know. Or you using a ipaddress backport to python 2 ?

trolldbois avatar Aug 21 '14 23:08 trolldbois

I'm using Python 2.7 and have installed the back-port of ipaddress. My test case is the example in the README. I hadn't realized that your codebase is Python3-only. Your code works fine in Python2 except for the call to "str(value)", which converts unicode to bytes, which ipaddress balks at.

dogwynn avatar Aug 24 '14 00:08 dogwynn

You can also install python-IPy which is supposed to be the python 2 solution. The code is working with 2.7+IPy or python 3 Le 23 août 2014 18:59, "dogwynn" [email protected] a écrit :

I'm using Python 2.7 and have installed the back-port of ipaddress. My test case is the example in the README. I hadn't realized that your codebase is Python3-only. Your code works fine in Python2 except for the call to "str(value)", which converts unicode to bytes, which ipaddress balks at.

— Reply to this email directly or view it on GitHub https://github.com/trolldbois/python-cymru-services/issues/1#issuecomment-53172775 .

trolldbois avatar Aug 24 '14 02:08 trolldbois