laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/37496?usp=email )


Change subject: pySim.esim.http_json_api: 'header' is not always present in 
response
......................................................................

pySim.esim.http_json_api: 'header' is not always present in response

For example, the ES9+ handleNotification function is defined with an
empty response body, so we cannot unconditionally assume that every HTTP
response will contain a JSON "header" value.

Change-Id: Ia3c5703b746c1eba91f85f8545f849a3f2d56e0b
---
M pySim/esim/http_json_api.py
1 file changed, 25 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/96/37496/1

diff --git a/pySim/esim/http_json_api.py b/pySim/esim/http_json_api.py
index 377faea..9c9349d 100644
--- a/pySim/esim/http_json_api.py
+++ b/pySim/esim/http_json_api.py
@@ -204,16 +204,17 @@
         return output
 
     def decode(self, data: dict) -> dict:
-        """[further] Decode and validate the JSON-Dict of the respnse body."""
+        """[further] Decode and validate the JSON-Dict of the response body."""
         output = {}
-        # let's first do the header, it's special
-        if not 'header' in data:
-            raise ValueError('Mandatory output parameter "header" missing')
-        hdr_class = self.output_params.get('header')
-        output['header'] = hdr_class.decode(data['header'])
+        if 'header' in self.output_params:
+            # let's first do the header, it's special
+            if not 'header' in data:
+                raise ValueError('Mandatory output parameter "header" missing')
+            hdr_class = self.output_params.get('header')
+            output['header'] = hdr_class.decode(data['header'])

-        if output['header']['functionExecutionStatus']['status'] not in 
['Executed-Success','Executed-WithWarning']:
-            raise ApiError(output['header']['functionExecutionStatus'])
+            if output['header']['functionExecutionStatus']['status'] not in 
['Executed-Success','Executed-WithWarning']:
+                raise ApiError(output['header']['functionExecutionStatus'])
         # we can only expect mandatory parameters to be present in case of 
successful execution
         for p in self.output_mandatory:
             if p == 'header':
@@ -253,4 +254,6 @@
         if not response.headers.get('X-Admin-Protocol', 
'gsma/rsp/v2.unknown').startswith('gsma/rsp/v2.'):
             raise HttpHeaderError(response)

-        return self.decode(response.json())
+        if response.content:
+            return self.decode(response.json())
+        return None

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37496?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia3c5703b746c1eba91f85f8545f849a3f2d56e0b
Gerrit-Change-Number: 37496
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-MessageType: newchange

Reply via email to