confluentinc / examples

Apache Kafka and Confluent Platform examples and demos
Apache License 2.0
1.91k stars 1.12k forks source link

ccloud_lib.py throws error if there is a new line in the librdkafka.config file #661

Open SmithJohnTaylor opened 4 years ago

SmithJohnTaylor commented 4 years ago

https://github.com/confluentinc/examples/tree/5.5.0-post/clients/cloud/python As per the docs, the config file should look like:

# Kafka
bootstrap.servers={{ BROKER_ENDPOINT }}
security.protocol=SASL_SSL
sasl.mechanisms=PLAIN
sasl.username={{ CLUSTER_API_KEY }}
sasl.password={{ CLUSTER_API_SECRET }}

# Confluent Cloud Schema Registry
schema.registry.url=https://{{ SR_ENDPOINT }}
basic.auth.credentials.source=USER_INFO
schema.registry.basic.auth.user.info={{ SR_API_KEY }}:{{ SR_API_SECRET }}

During runtime, ccloud_lib throws:

Traceback (most recent call last):
  File "./consumer_ccsr.py", line 39, in <module>
    conf = ccloud_lib.read_ccloud_config(config_file)
  File "/Users/jtsmith/confluent/examples/clients/cloud/python/ccloud_lib.py", line 130, in read_ccloud_config
    if line[0] != "#" and len(line) != 0:
IndexError: string index out of range

Upon removing the newline between sasl.password... and # Confluent Cloud... it works as expected.

It might be easier to update https://github.com/confluentinc/configuration-templates/blob/master/clients/cloud/librdkafka-sr.config than the code, but that's just my opinion! Leaving it up to the experts to decide.

ybyzek commented 4 years ago

@SmithJohnTaylor I didn't encounter this error in my environment using ./consumer_ccsr.py.

@rspurgeon did you encounter this error in your environment (asking especially since you are working on https://github.com/confluentinc/examples/pull/657 )?

ybyzek commented 4 years ago

Update: I can reproduce this, and here is the fix:

-            if line[0] != "#" and len(line) != 0:
+            if len(line) != 0 and line[0] != "#":

@rspurgeon can you add this into #657 ? If not, we'll make a separate PR.

rspurgeon commented 4 years ago

Update: I can reproduce this, and here is the fix:

-            if line[0] != "#" and len(line) != 0:
+            if len(line) != 0 and line[0] != "#":

@rspurgeon can you add this into #657 ? If not, we'll make a separate PR.

I can integrate it into #657

rspurgeon commented 4 years ago

657 has the change if anyone would like to review

sri101276 commented 2 years ago

@rspurgeon @ybyzek @SmithJohnTaylor Friends, Can you please tell me why I am getting the below error: Traceback (most recent call last): File "./consumernv2.py", line 50, in consumer = Consumer(consumer_conf) cimpl.KafkaException: KafkaError{code=_INVALID_ARG,val=-186,str="No such configuration property: "schema.registry.basic.auth.user.info""} (kafka-confluent) ssenapathy@scriptdev01: cimpl.KafkaException: KafkaError{code=_INVALID_ARG,val=-186,str="No such configuration property: "schema.registry.basic.auth.user.info""} I am using the latest branch 7.1.0-post.