Longer variable name

main
Bob Mottram 2024-07-19 12:16:38 +01:00
parent 12056b55c2
commit 7ef5fbad3b
1 changed files with 36 additions and 36 deletions

View File

@ -28,18 +28,18 @@ def create_session(proxy_type: str):
session = None session = None
try: try:
session = requests.session() session = requests.session()
except requests.exceptions.RequestException as ex: except requests.exceptions.RequestException as exc:
print('EX: requests error during create_session ' + str(ex)) print('EX: requests error during create_session ' + str(exc))
return None return None
except SocketError as ex: except SocketError as exc:
if ex.errno == errno.ECONNRESET: if exc.errno == errno.ECONNRESET:
print('EX: connection was reset during create_session ' + print('EX: connection was reset during create_session ' +
str(ex)) str(exc))
else: else:
print('EX: socket error during create_session ' + str(ex)) print('EX: socket error during create_session ' + str(exc))
return None return None
except ValueError as ex: except ValueError as exc:
print('EX: error during create_session ' + str(ex)) print('EX: error during create_session ' + str(exc))
return None return None
if not session: if not session:
return None return None
@ -93,8 +93,8 @@ def url_exists(session, url: str, timeout_sec: int = 3,
return True return True
print('url_exists for ' + url + ' returned ' + print('url_exists for ' + url + ' returned ' +
str(result.status_code)) str(result.status_code))
except BaseException: except BaseException as exc:
print('EX: url_exists GET failed ' + str(url)) print('EX: url_exists GET failed ' + str(url) + ' ' + str(exc))
return False return False
@ -150,27 +150,27 @@ def _get_json_request(session, url: str, session_headers: {},
if return_json: if return_json:
return result.json() return result.json()
return result.content return result.content
except requests.exceptions.RequestException as ex: except requests.exceptions.RequestException as exc:
session_headers2 = session_headers.copy() session_headers2 = session_headers.copy()
if session_headers2.get('Authorization'): if session_headers2.get('Authorization'):
session_headers2['Authorization'] = 'REDACTED' session_headers2['Authorization'] = 'REDACTED'
if debug and not quiet: if debug and not quiet:
print('EX: get_json failed, url: ' + str(url) + ', ' + print('EX: get_json failed, url: ' + str(url) + ', ' +
'headers: ' + str(session_headers2) + ', ' + 'headers: ' + str(session_headers2) + ', ' +
'params: ' + str(session_params) + ', ' + str(ex)) 'params: ' + str(session_params) + ', ' + str(exc))
except ValueError as ex: except ValueError as exc:
session_headers2 = session_headers.copy() session_headers2 = session_headers.copy()
if session_headers2.get('Authorization'): if session_headers2.get('Authorization'):
session_headers2['Authorization'] = 'REDACTED' session_headers2['Authorization'] = 'REDACTED'
if debug and not quiet: if debug and not quiet:
print('EX: get_json failed, url: ' + str(url) + ', ' + print('EX: get_json failed, url: ' + str(url) + ', ' +
'headers: ' + str(session_headers2) + ', ' + 'headers: ' + str(session_headers2) + ', ' +
'params: ' + str(session_params) + ', ' + str(ex)) 'params: ' + str(session_params) + ', ' + str(exc))
except SocketError as ex: except SocketError as exc:
if not quiet: if not quiet:
if ex.errno == errno.ECONNRESET: if exc.errno == errno.ECONNRESET:
print('EX: get_json failed, ' + print('EX: get_json failed, ' +
'connection was reset during get_json ' + str(ex)) 'connection was reset during get_json ' + str(exc))
return None return None
@ -363,19 +363,19 @@ def get_vcard(xml_format: bool,
print('EX: get_vcard failed, url: ' + str(url) + ', ' + print('EX: get_vcard failed, url: ' + str(url) + ', ' +
'headers: ' + str(session_headers2) + ', ' + 'headers: ' + str(session_headers2) + ', ' +
'params: ' + str(session_params) + ', ' + str(ex)) 'params: ' + str(session_params) + ', ' + str(ex))
except ValueError as ex: except ValueError as exc:
session_headers2 = session_headers.copy() session_headers2 = session_headers.copy()
if session_headers2.get('Authorization'): if session_headers2.get('Authorization'):
session_headers2['Authorization'] = 'REDACTED' session_headers2['Authorization'] = 'REDACTED'
if debug and not quiet: if debug and not quiet:
print('EX: get_vcard failed, url: ' + str(url) + ', ' + print('EX: get_vcard failed, url: ' + str(url) + ', ' +
'headers: ' + str(session_headers2) + ', ' + 'headers: ' + str(session_headers2) + ', ' +
'params: ' + str(session_params) + ', ' + str(ex)) 'params: ' + str(session_params) + ', ' + str(exc))
except SocketError as ex: except SocketError as exc:
if not quiet: if not quiet:
if ex.errno == errno.ECONNRESET: if exc.errno == errno.ECONNRESET:
print('EX: get_vcard failed, ' + print('EX: get_vcard failed, ' +
'connection was reset during get_vcard ' + str(ex)) 'connection was reset during get_vcard ' + str(exc))
return None return None
@ -586,27 +586,27 @@ def post_json(http_prefix: str, domain_full: str,
data=json.dumps(post_json_object), data=json.dumps(post_json_object),
headers=headers, timeout=timeout_sec, headers=headers, timeout=timeout_sec,
allow_redirects=True) allow_redirects=True)
except requests.Timeout as ex: except requests.Timeout as exc:
if not quiet: if not quiet:
print('EX: post_json timeout ' + inbox_url + ' ' + print('EX: post_json timeout ' + inbox_url + ' ' +
json.dumps(post_json_object) + ' ' + str(headers)) json.dumps(post_json_object) + ' ' + str(headers))
print(ex) print(exc)
return '' return ''
except requests.exceptions.RequestException as ex: except requests.exceptions.RequestException as exc:
if not quiet: if not quiet:
print('EX: post_json requests failed ' + inbox_url + ' ' + print('EX: post_json requests failed ' + inbox_url + ' ' +
json.dumps(post_json_object) + ' ' + str(headers) + json.dumps(post_json_object) + ' ' + str(headers) +
' ' + str(ex)) ' ' + str(exc))
return None return None
except SocketError as ex: except SocketError as exc:
if not quiet and ex.errno == errno.ECONNRESET: if not quiet and exc.errno == errno.ECONNRESET:
print('EX: connection was reset during post_json') print('EX: connection was reset during post_json')
return None return None
except ValueError as ex: except ValueError as exc:
if not quiet: if not quiet:
print('EX: post_json failed ' + inbox_url + ' ' + print('EX: post_json failed ' + inbox_url + ' ' +
json.dumps(post_json_object) + ' ' + str(headers) + json.dumps(post_json_object) + ' ' + str(headers) +
' ' + str(ex)) ' ' + str(exc))
return None return None
if post_result: if post_result:
return post_result.text return post_result.text
@ -640,20 +640,20 @@ def post_json_string(session, post_json_str: str,
session.post(url=inbox_url, data=post_json_str, session.post(url=inbox_url, data=post_json_str,
headers=headers, timeout=timeout_sec, headers=headers, timeout=timeout_sec,
allow_redirects=True) allow_redirects=True)
except requests.exceptions.RequestException as ex: except requests.exceptions.RequestException as exc:
if not quiet: if not quiet:
print('EX: error during post_json_string requests ' + str(ex)) print('EX: error during post_json_string requests ' + str(exc))
return None, None, 0 return None, None, 0
except SocketError as ex: except SocketError as exc:
if not quiet and ex.errno == errno.ECONNRESET: if not quiet and exc.errno == errno.ECONNRESET:
print('EX: connection was reset during post_json_string') print('EX: connection was reset during post_json_string')
if not quiet: if not quiet:
print('EX: post_json_string failed ' + inbox_url + ' ' + print('EX: post_json_string failed ' + inbox_url + ' ' +
post_json_str + ' ' + str(headers)) post_json_str + ' ' + str(headers))
return None, None, 0 return None, None, 0
except ValueError as ex: except ValueError as exc:
if not quiet: if not quiet:
print('EX: error during post_json_string ' + str(ex)) print('EX: error during post_json_string ' + str(exc))
return None, None, 0 return None, None, 0
if post_result.status_code < 200 or post_result.status_code > 204: if post_result.status_code < 200 or post_result.status_code > 204:
if post_result.status_code >= 400 and \ if post_result.status_code >= 400 and \