kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

TypeError: cafile should be a valid filesystem path -

Open fenchu opened this issue 4 years ago • 0 comments

Nomatter what I set the ssl_cafile to it give this error, the pem files are checked elsewhere and work.

The filepat verifies fine with os.path.isfile(ssl_cafile)

kafka.version '2.0.2' sys.version '3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]' windows10

vertical = "trk"
pw = f"{vertical}secret"
rootdir = os.getcwd()
ssl_cafile = f"{rootdir}\\{vertical}\\ca.pem",
ssl_certfile = f"{rootdir}\\{vertical}\\cert.pem",
ssl_keyfile = f"{rootdir}\\{vertical}\\key.pem",

servers = ['kaf-04-test-sz-os:9093','kaf-05-test-sz-os:9093','kaf-06-test-sz-os:9093']

# need this to get all topics
c1 = KafkaConsumer(
    bootstrap_servers=servers,
    security_protocol='SSL', 
    ssl_password=pw,
    ssl_cafile=my_ssl_cafile,
    ssl_certfile=my_ssl_certfile,
    ssl_keyfile=my_ssl_keyfile,
    #group_id='mortenb',
    consumer_timeout_ms=1000
)
Starting the Kafka producer
Added sensor with name connections-closed
Added sensor with name connections-created
Added sensor with name select-time
Added sensor with name io-time
Initiating connection to node bootstrap-1 at kaf-04-test-sz-os:9093
Added sensor with name bytes-sent-received
Added sensor with name bytes-sent
Added sensor with name bytes-received
Added sensor with name request-latency
Added sensor with name node-bootstrap-1.bytes-sent
Added sensor with name node-bootstrap-1.bytes-received
Added sensor with name node-bootstrap-1.latency
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <disconnected> [unspecified None]>: creating new socket
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <disconnected> [IPv4 ('10.200.210.54', 9093)]>: setting socket option (6, 1, 1)
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <connecting> [IPv4 ('10.200.210.54', 9093)]>: connecting to kaf-04-test-sz-os:9093 [('10.200.210.54', 9093) IPv4]
Probing node bootstrap-1 broker version
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <connecting> [IPv4 ('10.200.210.54', 9093)]>: established TCP connection
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <connecting> [IPv4 ('10.200.210.54', 9093)]>: initiating SSL handshake
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <handshake> [IPv4 ('10.200.210.54', 9093)]>: configuring default SSL Context
<BrokerConnection node_id=bootstrap-1 host=kaf-04-test-sz-os:9093 <handshake> [IPv4 ('10.200.210.54', 9093)]>: Loading SSL CA from ('C:\\dist\\work\\kafka-events\\trk\\ca.pem',)
Traceback (most recent call last):
  File "C:\dist\work\kafka-events\kafka-readall.py", line 25, in <module>
    producer = KafkaProducer(
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\producer\kafka.py", line 381, in __init__
    client = KafkaClient(metrics=self._metrics, metric_group_prefix='producer',
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\client_async.py", line 244, in __init__
    self.config['api_version'] = self.check_version(timeout=check_timeout)
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\client_async.py", line 909, in check_version
    version = conn.check_version(timeout=remaining, strict=strict, topics=list(self.config['bootstrap_topics_filter']))
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\conn.py", line 1238, in check_version
    if not self.connect_blocking(timeout_at - time.time()):
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\conn.py", line 340, in connect_blocking
    self.connect()
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\conn.py", line 401, in connect
    self._wrap_ssl()
  File "C:\dist\venvs\kafka\lib\site-packages\kafka\conn.py", line 473, in _wrap_ssl
    self._ssl_context.load_verify_locations(self.config['ssl_cafile'])
TypeError: cafile should be a valid filesystem path
(kafka) PS C:\dist\work\kafka-events> ls c:\\dist\\work\\kafka-events\trk\ca.pem
ls c:\\dist\\work\\kafka-events\trk\ca.pem


    Directory: C:\dist\work\kafka-events\trk


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        11/29/2021   4:19 PM           1344 ca.pem

fenchu avatar Nov 30 '21 08:11 fenchu