improved handling of expired QRZ.com session keys

This commit is contained in:
dh1tw 2015-04-14 01:39:57 +02:00
parent 6ae47d1442
commit 88a80525ad
4 changed files with 21 additions and 6 deletions

View file

@ -1,6 +1,14 @@
Changelog Changelog
--------- ---------
PyHamTools 0.5.1
================
14. April 2015
* improved handling of expired QRZ.com sessions
PyHamTools 0.5.0 PyHamTools 0.5.0
================ ================

View file

@ -52,7 +52,7 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'pyhamtools' project = u'pyhamtools'
copyright = u'2014, Tobias Wellnitz, DH1TW' copyright = u'2015, Tobias Wellnitz, DH1TW'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the

View file

@ -788,16 +788,23 @@ class LookupLib(object):
root = BeautifulSoup(response.text) root = BeautifulSoup(response.text)
lookup = {} lookup = {}
if root.error: #try to get a new session key and try to request again if root.error:
if re.search('Not found', root.error.text, re.I): #No data available for callsign if re.search('Not found', root.error.text, re.I): #No data available for callsign
raise KeyError(root.error.text) raise KeyError(root.error.text)
elif re.search('Session Timeout', root.error.text, re.I): # Get new session key
#try to get a new session key and try to request again
elif re.search('Session Timeout', root.error.text, re.I) or re.search('Invalid session key', root.error.text, re.I):
self._apikey = apikey = self._get_qrz_session_key(self._username, self._pwd) self._apikey = apikey = self._get_qrz_session_key(self._username, self._pwd)
response = self._request_callsign_info_from_qrz(callsign, apikey) response = self._request_callsign_info_from_qrz(callsign, apikey, apiv)
root = BeautifulSoup(response.text) root = BeautifulSoup(response.text)
#if this fails again, raise error
if root.error:
raise AttributeError(root.error.text) #most likely session key invalid
else: else:
raise AttributeError(root.error.text) #most likely session key missing or invalid raise AttributeError(root.error.text) #most likely session key missing
if root.callsign is None: if root.callsign is None:
raise ValueError raise ValueError

View file

@ -1,4 +1,4 @@
#VERSION = (0, 5, 0, 'dev') #VERSION = (0, 5, 0, 'dev')
VERSION = (0, 5, 0) VERSION = (0, 5, 1)
__release__ = ''.join(['-.'[type(x) == int]+str(x) for x in VERSION])[1:] __release__ = ''.join(['-.'[type(x) == int]+str(x) for x in VERSION])[1:]
__version__ = '.'.join((str(VERSION[0]), str(VERSION[1]))) __version__ = '.'.join((str(VERSION[0]), str(VERSION[1])))