From 09cb4a05526c73229428401f356251bbfe8bf1cd Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 20 Aug 2020 15:39:50 +0300 Subject: Add backward support for urllib * wqflask/base/trait.py: Remove unused imports * wqflask/db/call.py (Bench): Add urllib2 fallback for python2 --- wqflask/db/call.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'wqflask/db') diff --git a/wqflask/db/call.py b/wqflask/db/call.py index 3b8f782e..0971d2a2 100644 --- a/wqflask/db/call.py +++ b/wqflask/db/call.py @@ -3,7 +3,10 @@ from flask import g import string -import urllib.request, urllib.error, urllib.parse +try: # Python2 support + import urllib.request, urllib.error, urllib.parse +except: + import urllib2 import json from utility.tools import USE_GN_SERVER, LOG_SQL, GN_SERVER_URL from utility.benchmark import Bench @@ -59,7 +62,11 @@ def gn_server(path): """ with Bench("GN_SERVER", LOG_SQL): - res = urllib.request.urlopen(GN_SERVER_URL+path) + res = () + try: + res = urllib.request.urlopen(GN_SERVER_URL+path) + except: + res = urllib2.urlopen(GN_SERVER_URL+path) rest = res.read() res2 = json.loads(rest) logger.debug(res2) -- cgit v1.2.3