«SchemaError» возникает при проверке json - PullRequest
0 голосов
/ 20 октября 2019

Пример JSON:

enter       json_for_create_signal = {
            "signalType": "forex",
            "currencyFrom": "5c1e4633b140f7000f908897",
            "currencyTo": "5c1e4633b140f7000f908898",
            "currencyPair": "5cbd7faf496a8c001124ed5b",
            "type": "sell",
            "buyTip": {"value":21313},
            "stopTip": 21312.9999,
            "stopTipPips": "-1",
            "takeProfits": [{"value": 21313.0111, "isAchieved": False, "closeOnReach": False,
                             "pips": "+111"}],
            "status": "active",
            "orderType": "market"
    } 

здесь

Схема проверки:

enter         json_SCHEMA = {
            "signalType": {"type": "string"},
            "currencyFrom": {"type": "string"},
            "currencyTo": {"type": "string"},
            "currencyPair": {"type": "string"},
            "type": {"type": "string"},
            "buyTip": {"value": {"type": "number"}},
            "stopTip": {"type": "number"},
            "stopTipPips": {"type": "number"},
            "takeProfits": [{"value": {"type": "number"}, "isAchieved": {"type": "boolean"}, "closeOnReach":
                             {"type": "boolean"},
                             "pips": pips}],
            "status": {"type": "number"},
            "orderType": {"type": "number"}
    }

здесь

При проверке

enter  
  validate(instance={"signalType": "Forex"}, schema=json_SCHEMA) 

здесь

enter     @classmethod
def check_schema(cls, schema):
    for error in cls(cls.META_SCHEMA).iter_errors(schema):
      raise exceptions.SchemaError.create_from(error)

E jsonschema.exceptions.SchemaError: {'type': 'string'} недопустимо ни для одной из указанных схем

       Failed validating 'anyOf' in metaschema['properties']['type']:
           {'anyOf': [{'$ref': '#/definitions/simpleTypes'},
                      {'items': {'$ref': '#/definitions/simpleTypes'},
                       'minItems': 1,
                       'type': 'array',
                       'uniqueItems': True}]}

       On schema['type']:
           {'type': 'string'}  

здесь

venv / lib / python3.7 / site-packages / jsonschema / validators.py: 289: SchemaError

...