mirror of https://gitlab.com/bashrc2/epicyon
Consistent prefix for exception messages
parent
7bb310e811
commit
920fe5e2bf
42
session.py
42
session.py
|
@ -23,17 +23,17 @@ def create_session(proxy_type: str):
|
||||||
try:
|
try:
|
||||||
session = requests.session()
|
session = requests.session()
|
||||||
except requests.exceptions.RequestException as ex:
|
except requests.exceptions.RequestException as ex:
|
||||||
print('WARN: requests error during create_session ' + str(ex))
|
print('EX: requests error during create_session ' + str(ex))
|
||||||
return None
|
return None
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if ex.errno == errno.ECONNRESET:
|
if ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: connection was reset during create_session ' +
|
print('EX: connection was reset during create_session ' +
|
||||||
str(ex))
|
str(ex))
|
||||||
else:
|
else:
|
||||||
print('WARN: socket error during create_session ' + str(ex))
|
print('EX: socket error during create_session ' + str(ex))
|
||||||
return None
|
return None
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
print('WARN: error during create_session ' + str(ex))
|
print('EX: error during create_session ' + str(ex))
|
||||||
return None
|
return None
|
||||||
if not session:
|
if not session:
|
||||||
return None
|
return None
|
||||||
|
@ -114,7 +114,7 @@ def _get_json_request(session, url: str, domain_full: str, session_headers: {},
|
||||||
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('ERROR: 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(ex))
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
|
@ -122,13 +122,13 @@ def _get_json_request(session, url: str, domain_full: str, session_headers: {},
|
||||||
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('ERROR: 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(ex))
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
if ex.errno == errno.ECONNRESET:
|
if ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: get_json failed, ' +
|
print('EX: get_json failed, ' +
|
||||||
'connection was reset during get_json ' + str(ex))
|
'connection was reset during get_json ' + str(ex))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -310,23 +310,23 @@ def post_json(http_prefix: str, domain_full: str,
|
||||||
headers=headers, timeout=timeout_sec)
|
headers=headers, timeout=timeout_sec)
|
||||||
except requests.Timeout as ex:
|
except requests.Timeout as ex:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('ERROR: 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(ex)
|
||||||
return ''
|
return ''
|
||||||
except requests.exceptions.RequestException as ex:
|
except requests.exceptions.RequestException as ex:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('ERROR: 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(ex))
|
||||||
return None
|
return None
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if not quiet and ex.errno == errno.ECONNRESET:
|
if not quiet and ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: 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 ex:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('ERROR: 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(ex))
|
||||||
return None
|
return None
|
||||||
|
@ -360,18 +360,18 @@ def post_json_string(session, post_jsonStr: str,
|
||||||
headers=headers, timeout=timeout_sec)
|
headers=headers, timeout=timeout_sec)
|
||||||
except requests.exceptions.RequestException as ex:
|
except requests.exceptions.RequestException as ex:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('WARN: error during post_json_string requests ' + str(ex))
|
print('EX: error during post_json_string requests ' + str(ex))
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if not quiet and ex.errno == errno.ECONNRESET:
|
if not quiet and ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: connection was reset during post_json_string')
|
print('EX: connection was reset during post_json_string')
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('ERROR: post_json_string failed ' + inbox_url + ' ' +
|
print('EX: post_json_string failed ' + inbox_url + ' ' +
|
||||||
post_jsonStr + ' ' + str(headers))
|
post_jsonStr + ' ' + str(headers))
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('WARN: error during post_json_string ' + str(ex))
|
print('EX: error during post_json_string ' + str(ex))
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
if post_result.status_code < 200 or post_result.status_code > 202:
|
if post_result.status_code < 200 or post_result.status_code > 202:
|
||||||
if post_result.status_code >= 400 and \
|
if post_result.status_code >= 400 and \
|
||||||
|
@ -425,16 +425,16 @@ def post_image(session, attach_image_filename: str, federation_list: [],
|
||||||
post_result = session.post(url=inbox_url, data=media_binary,
|
post_result = session.post(url=inbox_url, data=media_binary,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
except requests.exceptions.RequestException as ex:
|
except requests.exceptions.RequestException as ex:
|
||||||
print('WARN: error during post_image requests ' + str(ex))
|
print('EX: error during post_image requests ' + str(ex))
|
||||||
return None
|
return None
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if ex.errno == errno.ECONNRESET:
|
if ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: connection was reset during post_image')
|
print('EX: connection was reset during post_image')
|
||||||
print('ERROR: post_image failed ' + inbox_url + ' ' +
|
print('ERROR: post_image failed ' + inbox_url + ' ' +
|
||||||
str(headers) + ' ' + str(ex))
|
str(headers) + ' ' + str(ex))
|
||||||
return None
|
return None
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
print('WARN: error during post_image ' + str(ex))
|
print('EX: error during post_image ' + str(ex))
|
||||||
return None
|
return None
|
||||||
if post_result:
|
if post_result:
|
||||||
return post_result.text
|
return post_result.text
|
||||||
|
@ -540,16 +540,16 @@ def download_image_any_mime_type(session, url: str,
|
||||||
try:
|
try:
|
||||||
result = session.get(url, headers=session_headers, timeout=timeout_sec)
|
result = session.get(url, headers=session_headers, timeout=timeout_sec)
|
||||||
except requests.exceptions.RequestException as ex:
|
except requests.exceptions.RequestException as ex:
|
||||||
print('ERROR: download_image_any_mime_type failed: ' +
|
print('EX: download_image_any_mime_type failed1: ' +
|
||||||
str(url) + ', ' + str(ex))
|
str(url) + ', ' + str(ex))
|
||||||
return None, None
|
return None, None
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
print('ERROR: download_image_any_mime_type failed: ' +
|
print('EX: download_image_any_mime_type failed2: ' +
|
||||||
str(url) + ', ' + str(ex))
|
str(url) + ', ' + str(ex))
|
||||||
return None, None
|
return None, None
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if ex.errno == errno.ECONNRESET:
|
if ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: download_image_any_mime_type failed, ' +
|
print('EX: download_image_any_mime_type failed, ' +
|
||||||
'connection was reset ' + str(ex))
|
'connection was reset ' + str(ex))
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue