From e1ef6e8c4ded14b95027c4a8260a1acdd43e3ce9 Mon Sep 17 00:00:00 2001 From: "Christian T. Jacobs" Date: Thu, 6 Jul 2017 23:09:56 +0100 Subject: [PATCH] Support Python 2.x version of urllib. --- pyqso/callsign_lookup.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pyqso/callsign_lookup.py b/pyqso/callsign_lookup.py index df23890..7dbdbe7 100644 --- a/pyqso/callsign_lookup.py +++ b/pyqso/callsign_lookup.py @@ -23,7 +23,10 @@ try: except ImportError: import httplib as http_client from xml.dom import minidom -import urllib +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from pyqso.auxiliary_dialogs import * @@ -51,9 +54,18 @@ class CallsignLookupQRZ: :rtype: bool """ logging.debug("Connecting to the qrz.com server...") + + # Percent-escape the password. + try: + password = quote(password) + except Exception as e: + logging.exception(e) + logging.error("Could not percent-escape the password. Falling back to non-percent-escaped password.") + pass + try: self.connection = http_client.HTTPConnection("xmldata.qrz.com") - request = "/xml/current/?username=%s;password=%s;agent=pyqso" % (username, urllib.parse.quote(password)) + request = "/xml/current/?username=%s;password=%s;agent=pyqso" % (username, password) self.connection.request("GET", request) response = self.connection.getresponse() except: @@ -177,9 +189,18 @@ class CallsignLookupHamQTH: """ logging.debug("Connecting to the hamqth.com server...") + + # Percent-escape the password. + try: + password = quote(password) + except Exception as e: + logging.exception(e) + logging.error("Could not percent-escape the password. Falling back to non-percent-escaped password.") + pass + try: self.connection = http_client.HTTPSConnection("www.hamqth.com") - request = "/xml.php?u=%s&p=%s" % (username, urllib.parse.quote(password)) + request = "/xml.php?u=%s&p=%s" % (username, password) self.connection.request("GET", request) response = self.connection.getresponse() except: