LFRequest.py: reduces volume of debug output

- headers not shown on 200 or 404
- headers not shown unless die_on_error_
- short 404 message now used

Signed-off-by: Jed Reynolds <jed@candelatech.com>
This commit is contained in:
Jed Reynolds
2021-03-09 00:51:22 -08:00
parent b414512f9d
commit 9a5f15ec9b

View File

@@ -180,11 +180,12 @@ class LFRequest:
try: try:
resp = request.urlopen(myrequest) resp = request.urlopen(myrequest)
resp_data = resp.read().decode('utf-8') resp_data = resp.read().decode('utf-8')
if (debug): if (debug and die_on_error_):
print("----- LFRequest::json_post:128 debug: --------------------------------------------") print("----- LFRequest::json_post:128 debug: --------------------------------------------")
print("URL: %s :%d "% (self.requested_url, resp.status)) print("URL: %s :%d "% (self.requested_url, resp.status))
LFUtils.debug_printer.pprint(resp.getheaders()) if resp.status != 200:
print("----- resp_data -------------------------------------------------") LFUtils.debug_printer.pprint(resp.getheaders())
print("----- resp_data:128 -------------------------------------------------")
print(resp_data) print(resp_data)
print("-------------------------------------------------") print("-------------------------------------------------")
responses.append(resp) responses.append(resp)
@@ -262,32 +263,32 @@ class LFRequest:
myrequest = request.Request(url=self.requested_url, myrequest = request.Request(url=self.requested_url,
headers=self.default_headers, headers=self.default_headers,
method=method_) method=method_)
myresponses = [] myresponses = []
try: try:
myresponses.append(request.urlopen(myrequest)) myresponses.append(request.urlopen(myrequest))
return myresponses[0] return myresponses[0]
except urllib.error.HTTPError as error: except urllib.error.HTTPError as error:
if debug: if debug:
print("----- LFRequest::get:181 HTTPError: --------------------------------------------") if error.code == 404:
print("<%s> HTTP %s: %s"%(myrequest.get_full_url(), error.code, error.reason, )) print("HTTP 404: <%s>" % myrequest.get_full_url())
if error.code != 404: else:
print("----- LFRequest::get:181 HTTPError: --------------------------------------------")
print("<%s> HTTP %s: %s"%(myrequest.get_full_url(), error.code, error.reason, ))
print("Error: ", sys.exc_info()[0]) print("Error: ", sys.exc_info()[0])
print("Request URL:", myrequest.get_full_url()) print("E Request URL:", myrequest.get_full_url())
print("Request Content-type:", myrequest.get_header('Content-type')) print("E Request Content-type:", myrequest.get_header('Content-type'))
print("Request Accept:", myrequest.get_header('Accept')) print("E Request Accept:", myrequest.get_header('Accept'))
print("Request Data:") print("E Request Data:")
LFUtils.debug_printer.pprint(myrequest.data) LFUtils.debug_printer.pprint(myrequest.data)
if error.headers: if (error.code != 404) and error.headers:
# the HTTPError is of type HTTPMessage a subclass of email.message # the HTTPError is of type HTTPMessage a subclass of email.message
# print(type(error.keys())) # print(type(error.keys()))
for headername in sorted(error.headers.keys()): for headername in sorted(error.headers.keys()):
print ("Response %s: %s "%(headername, error.headers.get(headername))) print ("H Response %s: %s "%(headername, error.headers.get(headername)))
if len(myresponses) > 0: if (error.code != 404) and (len(myresponses) > 0):
print("----- Response: --------------------------------------------------------") print("----- Response: --------------------------------------------------------")
LFUtils.debug_printer.pprint(myresponses[0].reason) LFUtils.debug_printer.pprint(myresponses[0].reason)
print("------------------------------------------------------------------------") print("------------------------------------------------------------------------")
if (error.code != 404) and (die_on_error_ == True): if (error.code != 404) and (die_on_error_ == True):
traceback.print_stack(limit=15) traceback.print_stack(limit=15)
exit(1) exit(1)