This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_uncaught_exceptions(e, value, tb): | |
""" https://stackoverflow.com/questions/8050775/using-pythons-logging-module-to-log-all-exceptions-and-errors/8054179#8054179 """ | |
log.exception(f"API Uncaught exception: {e}{value}") | |
traceback.print_tb(tb) | |
sys.excepthook = handle_uncaught_exceptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_email(subject="Website:", to="webmail@domain.com", body={'field': 'empty'}): | |
""" | |
GIVEN A SUBJECT, TO ADDRESS AND AN OBJECT, | |
SEND THE EMAIL VIA AWS SIMPLE EMAIL SERVICE | |
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ses.html | |
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html | |
""" | |
# FROM email address. A constant defined elsewhere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_email(email_address): | |
""" | |
Validate an email address. | |
We selected a "simple" validation with has a bias toward | |
letting more edge cases through rather than block them. | |
We want the feedback. | |
Returns True if the email is valid. False is not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.client import HTTPConnection | |
# enable/disable urllib logging | |
HTTPConnection.debuglevel = 0 | |
requests_log = logging.getLogger("urllib3") | |
requests_log.setLevel(logging.INFO) | |
requests_log.propagate = True |