gpt4 book ai didi

python - kafka-python 生产者 - SSL 连接失败 - 仅限 Trustore

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:58 25 4
gpt4 key购买 nike

我正在尝试通过 python 将消息发布到 kafka 主题,但收到错误消息。我可以通过 CLI 进行连接和发布。希望得到一些指导。我用谷歌搜索并阅读了文档。谢谢!!

成功的 CLI 命令:

 kafka-console-producer --broker-list 
123.45.67.891:1234,123.45.67.892:1234,123.45.67.893:1234 --
producer.config C:\Users\fake_user\Kafka\client-ssl.properties --topic FakeTopic

Contents of client-ssl.properties:
security.protocol = SSL
ssl.truststore.location = C:/Users/fake_user/Kafka/kafka-truststore
ssl.truststore.password = fakepass

代码:

from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers=['123.45.67.891:1234', '123.45.67.892:1234', '123.45.67.893:1234'],
security_protocol='SSL',
ssl_certfile=r'C:\Users\fake_user\Kafka\kafka-truststore',
ssl_password='fakepass')

producer.send('FakeTopic', value='python_test', key='test')

结果错误:

Traceback (most recent call last):
File "kafka_post_test.py", line 6, in <module>
ssl_password='fakepass')
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\producer\kafka.py", line 381, in __init__
**self.config)
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\client_async.py", line 239, in __init__
self.config['api_version'] = self.check_version(timeout=check_timeout)
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\client_async.py", line 874, in check_version
version = conn.check_version(timeout=remaining, strict=strict, topics=list(self.config['bootstrap_topics_filter']))
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\conn.py", line 1078, in check_version
if not self.connect_blocking(timeout_at - time.time()):
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\conn.py", line 331, in connect_blocking
self.connect()
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\conn.py", line 420, in connect
if self._try_handshake():
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kafka\conn.py", line 496, in _try_handshake
self._sock.do_handshake()
File "C:\Users\fake_user\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1051)

最佳答案

看看这个 link.

对于几乎所有由 Java 运行的程序,您都必须将 SSL 证书添加到 JVM keystore 。

关于python - kafka-python 生产者 - SSL 连接失败 - 仅限 Trustore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56498030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com