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

kafka.errors.NodeNotReadyError: NodeNotReadyError

Open StudyForZX opened this issue 5 years ago • 4 comments

kafka-python=2.0.1

kafka_version=2.5.0

code is

from kafka.admin import KafkaAdminClient

self.adminClient = KafkaAdminClient(
            bootstrap_servers = 'borker:9092',
            api_version = (0, 10),
            security_protocol = 'PLAINTEXT',
        )

kafka and zk has no problems.

StudyForZX avatar Jul 23 '20 09:07 StudyForZX

Check this https://github.com/dpkp/kafka-python/issues/1861 and this https://www.confluent.io/blog/kafka-listeners-explained/

tl;dr: You need to set advertised.listeners (or KAFKA_ADVERTISED_LISTENERS if you’re using Docker images) to the external address (host/IP) so that clients can correctly connect to it. Otherwise, they’ll try to connect to the internal host address—and if that’s not reachable, then problems ensue.

mmenbawy avatar Oct 12 '20 08:10 mmenbawy

kafka-python version

crc32c==2.2
kafka-python==2.0.2
kazoo==2.8.0
  - six [required: Any, installed: 1.15.0]

partial docker-compose file


 environment:
      KAFKA_BROKER_ID: 2
      KAFKA_ADVERTISED_HOST_NAME: 10.0.75.2                 
      KAFKA_ADVERTISED_PORT: 9094                              
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.0.75.2:9094  
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181"

This is my code below


class KafkaDemo(object):

    @classmethod
    def admin(cls):
        client = KafkaAdminClient(
            bootstrap_servers=[
                '127.0.0.1:9093',
                '127.0.0.1:9094',
                '127.0.0.1:9095'
            ],
            client_id='client-two'
        )
        print(f'Client config: {client.config}')
    
        cluster=client.describe_cluster()

        #topics

        t1 = NewTopic(name='topic1-test', num_partitions=3,replication_factor=1)
        client.create_topics([t1])
        t_info=client.describe_topics(['topic1-test'])
        print(t_info)
        client.delete_topics(['topic1-test'])
        
		client.close()
		
if __name__ == '__main__':
    KafkaDemo.admin()

Error

Connected to pydev debugger (build 202.7660.27)
Traceback (most recent call last):
  File "C:\Users\Administrator\.virtualenvs\distrubution-bUBhtHd3\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:\Users\Administrator\.virtualenvs\distrubution-bUBhtHd3\lib\site-packages\kafka\conn.py", line 1240, in check_version
    raise Errors.NodeNotReadyError()
kafka.errors.NodeNotReadyError: NodeNotReadyError
python-BaseException

After the first connection is successful, it can run normally, but once the program reports an error midway, after closing the program, the connection will report an error again

AntmanTmp avatar Oct 23 '20 07:10 AntmanTmp

My environment:

  • Kubernetes v1.23.7
  • Deploy kafka&zookeeper with YAML I set the NodePort to the kafka Service. But I can't use NodeIP:NodePort as bootstrap-server address. It report same error: kafka.errors.NoBrokersAvailable: NoBrokersAvailable

cuiyuanyuan542 avatar Mar 07 '23 03:03 cuiyuanyuan542

My environment:

  • Kubernetes v1.23.7
  • Deploy kafka&zookeeper with YAML I set the NodePort to the kafka Service. But I can't use NodeIP:NodePort as bootstrap-server address. It report same error: kafka.errors.NoBrokersAvailable: NoBrokersAvailable

I don't know how the kafka env variables in YAML add

cuiyuanyuan542 avatar Mar 08 '23 01:03 cuiyuanyuan542