[英]Unable to register schema using register() in python
I am trying to register schema to confluent schema registry using python.我正在尝试使用 python 将模式注册到融合模式注册表。
from schema_registry.client import SchemaRegistryClient
subject_name = "new-schema"
schema_url = "https://{{ schemaRegistry }}:8081"
sr = SchemaRegistryClient(schema_url)
schema = {"namespace": "example.avro",
"type": "record",
"name": "user",
"fields": [
{"name": "fname", "type": "string"},
{"name": "favorite_number", "type": "int"}
]
}
my_schema = sr.register(subject_name, schema)
I am getting error as我收到错误
AttributeError: 'dict' object has no attribute 'name'
This is a valid avro schema.这是一个有效的 avro 模式。 Still getting this error.
仍然收到此错误。 What is that I am missing in here?
我在这里缺少什么?
Any help would be appreciated.任何帮助,将不胜感激。
Instead of a dict
, try to pass schema_registry.client.schema.AvroSchema
:尝试传递
schema_registry.client.schema.AvroSchema
而不是dict
:
from schema_registry.client import SchemaRegistryClient, schema
schema_ = schema.AvroSchema({
"namespace": "example.avro",
"type": "record",
"name": "user",
"fields": [
{"name": "fname", "type": "string"},
{"name": "favorite_number", "type": "int"}
]
})
my_schema = sr.register(subject_name, schema_)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.