Python Цербер показывает действительное поле как «неизвестное поле» - PullRequest
0 голосов
/ 11 февраля 2020

Это мой код для справки:

import re
from cerberus import Validator


def address_check(field, value, error):
    if re.search('^[0-9]+( [A-Z]+)+$', str(value).upper()) is None:
        error(field, "Must be comprised of a street number with a street name")


def zipcode_check(field, value, error):
    if re.search('^[A-Z][1-9][A-Z] [1-9][A-Z][1-9]$', str(value).upper()) is None:
        error(field, "Postal code must be comprised in the format of {LNL NLN}")

schema = {'firstname:': {'type': 'string'},
      'lastname:': {'type': 'string'},
      'middlename': {'type': 'string', 'nullable': True},
      'ssn': {'type': 'integer', 'maxlength': 9, 'minlength': 9},
      'address': {'type': 'string', 'check_with': address_check},
      'city': {'type': 'string'},
      'state': {'type': 'string', 'maxlength': 2, 'minlength': 2},
      'zipcode': {'type': 'string', 'check_with': zipcode_check},
      'country': {'type': 'string', 'allowed': ['840', '006']},
      'proxykey': {'type': 'integer', 'minlength': 19, 'maxlength': 19, 'nullable': True},
      'loadamount': {'type': 'integer'},
      'status': {'type': 'string', 'allowed': ['ACTIVATE', 'CLOSE', 'SUSPEND', 'UNSUSPEND', 'LOSTSTOLEN', 'MARK_PFRAUD', 'UNMARK_PFRAUD', 'MARK_FRAUD']},
      'newpin': {
          'anyof': [
              {
                  'type': 'integer',
                  'maxlength': 4,
                  'minlength': 4
              },
              {
                  'type': 'string',
                  'allowed': ['RANDOM']
              }
          ]
          }
      }

v = Validator(schema)


def create_fis_user_check(firstname, lastname, ssn, address, city, state,
                      zipcode, country, middlename=None, proxykey=None):

    data = {'firstname': firstname, "lastname": lastname, "ssn": ssn, "address": address,
        "city": city, "state": state, "zipcode": zipcode, "country": country, "middlename": middlename, "proxykey": proxykey}

    return v.validate(data, schema)


check1 = create_fis_user_check("bob", "smith", 333333333, "21 test way", "af", "af", "L4C 1N1", '840')

print(v.errors)

Когда я запускаю этот код, v.errors показывает, что «имя» и «фамилия» являются неизвестными полями. На протяжении жизни я не могу понять, почему эта ошибка происходит. Это часть моей схемы, и другие поля, которые являются просто типом строки, принимаются нормально, поэтому я не понимаю, почему эти два не являются.

Любая помощь будет оценена.

...