我正在使用有效的日期时间字符串使用JSON架构formatchecker在数据中进行验证,但它没有验证此有效的日期时间格式,因此失败,并出现以下错误:
jsonschema.exceptions.ValidationError: '2013-09-16T15:40:16.21211' is not a 'date-time'
我的代码:
import jsonschema
import json
data = {"timestamp": "2013-09-16T15:40:16.21211"}
schema ="""{
"type":"object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"required":true,
"properties":{
"timestamp": {
"format" :"date-time",
"type":"string",
"required" :false
}
}}"""
jsonschema.validate(data,json.loads(schema),format_checker=jsonschema.FormatChecker())
date-time
验证器requires the format(“日期和时间格式名称源自RFC 3339,第5.6节”)与RFC3339中指定的一致:规范的
full-time
部分要求指定time-offset
,即必须在datetime之后添加Z
,以表示时间是UTC,或者必须添加显式偏移量(即+0100等)。你知道吗相关问题 更多 >
编程相关推荐