mozilla/cipherscan

analyze.py not python3 compatible

slavkoja opened this issue · 3 comments

I updated my copy from 2015 year and i found, that the new version of analyze.py is not compatible with python3 due urllib2 import:

Traceback (most recent call last):
  File "./analyze.py", line 10, in <module>
    import sys, os, json, subprocess, logging, argparse, platform, urllib2, re
ModuleNotFoundError: No module named 'urllib2'

2to3 is able to solve it, but i did it manually to make it both py2 & py3 compatible:

diff --git a/analyze.py b/analyze.py
index c886ee8..32a16fe 100755
--- a/analyze.py
+++ b/analyze.py
@@ -7,7 +7,14 @@
 
 from __future__ import print_function
 
-import sys, os, json, subprocess, logging, argparse, platform, urllib2, re
+import sys, os, json, subprocess, logging, argparse, platform, re
+
+try:
+    from urllib2 import urlopen, URLError
+except ModuleNotFoundError:
+    from urllib.request import urlopen
+    from urllib.error import URLError
+
 from collections import namedtuple
 from datetime import datetime
 from copy import deepcopy
@@ -400,10 +407,10 @@ def build_ciphers_lists():
     sstlsurl = "https://statics.tls.security.mozilla.org/server-side-tls-conf.json"
     conf = dict()
     try:
-        raw = urllib2.urlopen(sstlsurl).read()
+        raw = urlopen(sstlsurl).read()
         conf = json.loads(raw)
         logging.debug('retrieving online server side tls recommendations from %s' % sstlsurl)
-    except urllib2.URLError:
+    except URLError:
         with open('server-side-tls-conf.json', 'r') as f:
             conf = json.load(f)
             logging.debug('Error connecting to %s; using local archive of server side tls recommendations' % sstlsurl)

regards

could you prepare a PR with this change?

Close issue if the fix is merged?