Skip to content

Commit a03dca1

Browse files
committed
Fixed #145 - Add code to test is the provided api_url valid or not.
1 parent 9782e0e commit a03dca1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

about_code_tool/genabout.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ def request_license_data(self, url, username, api_key, license_key):
289289
'format': 'json'
290290
}
291291

292+
# Check is the provided api_url valid or not.
293+
try:
294+
request = urllib2.Request(url)
295+
response = urllib2.urlopen(request)
296+
response_content = response.read()
297+
except urllib2.HTTPError as http_e:
298+
if http_e.code == 404:
299+
error_msg = ("URL not reachable. Invalid '--api_url'."
300+
" LICENSE generation is skipped.")
301+
print("\n" + error_msg + "\n")
302+
self.extract_dje_license_error = True
303+
self.errors.append(Error('--api_url', url, error_msg))
304+
292305
url = url.rstrip('/')
293306
encoded_payload = urllib.urlencode(payload)
294307
full_url = '%(url)s/%(license_key)s/?%(encoded_payload)s' % locals()

0 commit comments

Comments
 (0)