diff --git a/create_election/director_jobs.py b/create_election/director_jobs.py index f8e7cea..641e663 100644 --- a/create_election/director_jobs.py +++ b/create_election/director_jobs.py @@ -27,7 +27,7 @@ from vmn import * from taskqueue import end_task - + @decorators.local_task @decorators.task(action="create_election", queue="launch_task") class CreateElectionTask(TaskHandler): @@ -141,10 +141,11 @@ def handle_error(self, error): input_data = self.task.get_data()['input_data'] election_id = input_data['election_id'] election = db.session.query(Election)\ - .filter(Election.session_id == election_id).first() + .filter(Election.id == election_id).first() session = requests.sessions.Session() callback_url = election.callback_url + print("callback_url, " + callback_url) fail_data = { "status": "error", "reference": { @@ -158,9 +159,19 @@ def handle_error(self, error): ssl_calist_path = app.config.get('SSL_CALIST_PATH', '') ssl_cert_path = app.config.get('SSL_CERT_PATH', '') ssl_key_path = app.config.get('SSL_KEY_PATH', '') - print("\ncallback_url " + callback_url) - r = session.request('post', callback_url, data=dumps(fail_data), - verify=ssl_calist_path, cert=(ssl_cert_path, ssl_key_path)) + try: + r = session.request( + 'post', + callback_url, + data=dumps(fail_data), + headers={'content-type': 'application/json'}, + verify=ssl_calist_path, + cert=(ssl_cert_path, ssl_key_path) + ) + except Exception as post_error: + print("exception calling to callback_url:") + print(post_error) + raise post_error finally: end_task() diff --git a/tally_election/director_jobs.py b/tally_election/director_jobs.py index 1017ded..a215835 100644 --- a/tally_election/director_jobs.py +++ b/tally_election/director_jobs.py @@ -112,6 +112,7 @@ def handle_error(self, error): input_data = self.task.get_data()['input_data'] election_id = input_data['election_id'] callback_url = input_data['callback_url'] + print("callback_url, " + callback_url) election = db.session.query(Election)\ .filter(Election.id == election_id).first() @@ -130,15 +131,20 @@ def handle_error(self, error): ssl_cert_path = app.config.get('SSL_CERT_PATH', '') ssl_key_path = app.config.get('SSL_KEY_PATH', '') print("\nFF callback_url4 " + callback_url) - r = session.request( - 'post', - callback_url, - data=dumps(fail_data), - headers={'content-type': 'application/json'}, - verify=ssl_calist_path, - cert=(ssl_cert_path, ssl_key_path) - ) - print(r.text) + try: + r = session.request( + 'post', + callback_url, + data=dumps(fail_data), + headers={'content-type': 'application/json'}, + verify=ssl_calist_path, + cert=(ssl_cert_path, ssl_key_path) + ) + print(r.text) + except Exception as post_error: + print("exception calling to callback_url:") + print(post_error) + raise post_error finally: end_task()