title: kafka-python: producer is not able to connect
body: <p>kafka-python (1.0.0) throws error while connecting to the broker.
  At the same time /usr/bin/kafka-console-producer and /usr/bin/kafka-console-consumer work fine.</p>
  
  <p>Python application used to work well also, but after zookeeper restart, it no longer can connect.</p>
  
  <p>I am using bare bones example from the docs:</p>
  
  <pre><code>from kafka import KafkaProducer
  from kafka.common import KafkaError
  
  producer = KafkaProducer(bootstrap_servers=['hostname:9092'])
  
  # Asynchronous by default
  future = producer.send('test-topic', b'raw_bytes')
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>Traceback (most recent call last):   File "pp.py", line 4, in &lt;module&gt;
      producer = KafkaProducer(bootstrap_servers=['hostname:9092'])   File "/usr/lib/python2.6/site-packages/kafka/producer/kafka.py", line 246, in __init__
      self.config['api_version'] = client.check_version()   File "/usr/lib/python2.6/site-packages/kafka/client_async.py", line 629, in check_version
      connect(node_id)   File "/usr/lib/python2.6/site-packages/kafka/client_async.py", line 592, in connect
      raise Errors.NodeNotReadyError(node_id) kafka.common.NodeNotReadyError: 0 Exception AttributeError: "'KafkaProducer' object has no attribute '_closed'" in &lt;bound method KafkaProducer.__del__ of &lt;kafka.producer.kafka.KafkaProducer object at 0x7f6171294c50&gt;&gt; ignored
  </code></pre>
  
  <p>When stepping through ( /usr/lib/python2.6/site-packages/kafka/client_async.py) I noticed that line 270 evaluates as false:</p>
  
  <pre><code>270         if not self._metadata_refresh_in_progress and not self.cluster.ttl() == 0:
  271             if self._can_send_request(node_id):
  272                 return True
  273         return False
  </code></pre>
  
  <p>In my case  self._metadata_refresh_in_progress is False, but the ttl() = 0;</p>
  
  <p>At the same time kafka-console-* are happily pushing messages around:</p>
  
  <pre><code>/usr/bin/kafka-console-producer --broker-list hostname:9092 --topic test-topic
  hello again
  hello2
  </code></pre>
  
  <p>Any advice?</p>