Python 3.x 尝试使用confluent_kafka python将csv文件推送到卡夫卡主题时出错
我正在尝试使用AvroProducer将csv文件推送到卡夫卡主题。我正在读取一个csv文件,并在卡夫卡主题中逐行循环。csv文件有10列,与value\u schema\u str变量中定义的相同。但是我犯了一个错误。使用python3.7、avro-python3 1.8.2和confluent_kafka 运行Producer.py时出现此错误Python 3.x 尝试使用confluent_kafka python将csv文件推送到卡夫卡主题时出错,python-3.x,kafka-producer-api,confluent-schema-registry,confluent-platform,Python 3.x,Kafka Producer Api,Confluent Schema Registry,Confluent Platform,我正在尝试使用AvroProducer将csv文件推送到卡夫卡主题。我正在读取一个csv文件,并在卡夫卡主题中逐行循环。csv文件有10列,与value\u schema\u str变量中定义的相同。但是我犯了一个错误。使用python3.7、avro-python3 1.8.2和confluent_kafka 运行Producer.py时出现此错误 Traceback (most recent call last): File "/anaconda3/lib/python3.7/site-
Traceback (most recent call last):
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/anaconda3/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/anaconda3/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/anaconda3/lib/python3.7/http/client.py", line 278, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: P
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/anaconda3/lib/python3.7/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/anaconda3/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/anaconda3/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/anaconda3/lib/python3.7/http/client.py", line 278, in _read_status
raise BadStatusLine(line)
urllib3.exceptions.ProtocolError: ('Connection aborted.', BadStatusLine('\x15\x03\x03\x00\x02\x02P'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "producer.py", line 97, in <module>
avroProducer.produce(topic='UserActivity', value=row)
File "/anaconda3/lib/python3.7/site-packages/confluent_kafka/avro/__init__.py", line 80, in produce
value = self._serializer.encode_record_with_schema(topic, value_schema, value)
File "/anaconda3/lib/python3.7/site-packages/confluent_kafka/avro/serializer/message_serializer.py", line 105, in encode_record_with_schema
schema_id = self.registry_client.register(subject, schema)
File "/anaconda3/lib/python3.7/site-packages/confluent_kafka/avro/cached_schema_registry_client.py", line 215, in register
result, code = self._send_request(url, method='POST', body=body)
File "/anaconda3/lib/python3.7/site-packages/confluent_kafka/avro/cached_schema_registry_client.py", line 164, in _send_request
response = self._session.request(method, url, headers=_headers, json=body)
File "/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('\x15\x03\x03\x00\x02\x02P'))
错误提示您无法连接到注册表您是否考虑过使用Kafka connect执行此操作?kafka connect spooldir连接器获取CSV文件并将其发送到kafka主题。比自己编写代码容易得多:)错误提示您无法连接到注册表您是否考虑过使用Kafka connect来执行此操作?kafka connect spooldir连接器获取CSV文件并将其发送到kafka主题。比自己编写代码容易得多:)