From a5ba87bd3126147c176e5729d2c8c329098fe511 Mon Sep 17 00:00:00 2001 From: endbro Date: Wed, 27 Apr 2022 09:54:35 +0200 Subject: [PATCH] FIX-01: http 500 err, base img, requirements --- Dockerfile | 2 +- service/requirements.txt | 4 ++-- service/service.py | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d14636..0d40034 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3-alpine +FROM python:3.9-alpine3.15 LABEL author="Endre Brønnum" LABEL author.email="endre.bronnum@sesam.io" diff --git a/service/requirements.txt b/service/requirements.txt index 0199541..2da8e1e 100644 --- a/service/requirements.txt +++ b/service/requirements.txt @@ -1,4 +1,4 @@ xmltodict==0.12.0 -requests==2.10.0 -Flask==2.0.1 +requests==2.27.1 +Flask==2.1.1 PyYAML==5.1 \ No newline at end of file diff --git a/service/service.py b/service/service.py index a70fd56..10e399d 100644 --- a/service/service.py +++ b/service/service.py @@ -4,7 +4,7 @@ import yaml from xml.parsers.expat import ExpatError -from flask import Flask, request, Response, jsonify +from flask import Flask, abort, request, Response, jsonify import os import requests @@ -140,7 +140,7 @@ def xml_string_to_json(): - xml attributes will be prefixed by "@" in the json data - accepts entities with non-existing XML string """ - + if(not request.is_json): return "Request body was not JSON", 400 @@ -159,7 +159,8 @@ def emit_entities(): # Sesam packs entities in an array before firing off a request and expects an array back.  yield '[' first = True - for item in request_payload: + for item in request_payload: + currentItem = item["_id"] if not first: yield ',' else: @@ -189,7 +190,8 @@ def emit_entities(): yield ']' except Exception as ex: - logger.error(f"Exiting with error: {ex}") + logger.error(f"Exiting with error: {ex} - suspected entity = {currentItem}") + abort(500) return Response(response=emit_entities(), mimetype='application/json')