mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 12:18:00 +00:00
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:
@@ -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))
|
||||||
|
if resp.status != 200:
|
||||||
LFUtils.debug_printer.pprint(resp.getheaders())
|
LFUtils.debug_printer.pprint(resp.getheaders())
|
||||||
print("----- resp_data -------------------------------------------------")
|
print("----- resp_data:128 -------------------------------------------------")
|
||||||
print(resp_data)
|
print(resp_data)
|
||||||
print("-------------------------------------------------")
|
print("-------------------------------------------------")
|
||||||
responses.append(resp)
|
responses.append(resp)
|
||||||
@@ -262,29 +263,29 @@ 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:
|
||||||
|
if error.code == 404:
|
||||||
|
print("HTTP 404: <%s>" % myrequest.get_full_url())
|
||||||
|
else:
|
||||||
print("----- LFRequest::get:181 HTTPError: --------------------------------------------")
|
print("----- LFRequest::get:181 HTTPError: --------------------------------------------")
|
||||||
print("<%s> HTTP %s: %s"%(myrequest.get_full_url(), error.code, error.reason, ))
|
print("<%s> HTTP %s: %s"%(myrequest.get_full_url(), error.code, error.reason, ))
|
||||||
if error.code != 404:
|
|
||||||
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("------------------------------------------------------------------------")
|
||||||
|
|||||||
Reference in New Issue
Block a user