From e92d2d643ba1ba4b548a5bbecb3f94e0c8a16ac5 Mon Sep 17 00:00:00 2001 From: Glen Robson Date: Fri, 25 Oct 2019 14:58:45 +0100 Subject: [PATCH] Handling if the context is just a string rather than a dict --- schema/schemavalidator.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/schema/schemavalidator.py b/schema/schemavalidator.py index 0e3b052..2e30e07 100755 --- a/schema/schemavalidator.py +++ b/schema/schemavalidator.py @@ -54,14 +54,15 @@ def validate(data, version, url): print('\n Path for error: {}'.format(printPath(err.path, err.message))) context = err.instance print (json.dumps(err.instance, indent=4)) - for key in context: - print('****') - print(key) - print('****') - if isinstance(context[key], list): - context[key] = '[ ... ]' - elif isinstance(context[key], dict): - context[key] = '{ ... }' + if isinstance(context, dict): + for key in context: + print('****') + print(key) + print('****') + if isinstance(context[key], list): + context[key] = '[ ... ]' + elif isinstance(context[key], dict): + context[key] = '{ ... }' errorsJson.append({ 'title': 'Error {} of {}.\n Message: {}'.format(errorCount, len(errors), err.message), 'detail': detail,