AvroTypeException(self.writer_schema,基准)

时间:2018-07-12 23:26:19

标签: python-3.x apache-kafka confluent

我遇到此错误,请寻求任何建议。使用以下命令运行融合企业4.1.1:

::我的架构(2col.avsc)::

{"namespace": "com.example.avro",
"type": "record",
"name": "sor1",
"fields": [
{"name": "SRCE_BOOK_BRNCH", "int": "int"},
{"name": "NUM_FCLTY", "type": ["string", "null"], "default": null}]}

::我的CSV(2col.csv)::

3110,
3110,
3110,1.30E + 12
...

::我的代码::

from confluent_kafka import avro
from confluent_kafka.avro import AvroProducer
import csv

AvroProducerConf = {'bootstrap.servers': '10.97.176.201:9092,10.97.176.202:9092,10.97.176.203:9092','schema.registry.url': 'http://localhost:8081'}

value_schema = avro.load('2col.avsc')

avroProducer = AvroProducer(AvroProducerConf, default_value_schema = value_schema)

with open('2col.csv', newline = '', encoding = 'utf-8') as f:
reader = csv.reader(f, delimiter = ',')
for row in reader:
    avroProducer.produce(topic = '2col', value = {"SRCE_BOOK_BRNCH": row[0],"NUM_FCLTY": row[1]})
    print(row)
    avroProducer.flush()

::我的错误::
...   写入文件“ /apps/home/kafka/.local/lib/python3.6/site-packages/avro/io.py”,第809行

引发AvroTypeException(self.writer_schema,数据)

avro.io.AvroTypeException:数据{'SRCE_BOOK_BRNCH':'3110','NUM_FCLTY':''}不是架构{...

的示例

有什么想法吗?

提前谢谢!

ravi

0 个答案:

没有答案