title: kafka-python 1.3.3: KafkaProducer.send with explicit key fails to send message to broker
body: <p>(<em>Possibly</em> a duplicate of <a href="https://stackoverflow.com/q/28412028/1337498">Can&#39;t send a keyedMessage to brokers with partitioner.class=kafka.producer.DefaultPartitioner</a>, although the OP of that question didn't mention kafka-python. And anyway, it never got an answer.)</p>
  
  <p>I have a Python program that has been successfully (for many months) sending messages to the Kafka broker, using essentially the following logic:</p>
  
  <pre><code>producer = kafka.KafkaProducer(bootstrap_servers=[some_addr],
                                 retries=3)
  ...
  msg = json.dumps(some_message)
  res = producer.send(some_topic, value=msg)
  </code></pre>
  
  <p>Recently, I tried to upgrade it to send messages to different partitions based on a definite key value extracted from the message:</p>
  
  <pre><code>producer = kafka.KafkaProducer(bootstrap_servers=[some_addr],
                                 key_serializer=str.encode,
                                 retries=3)
  ...
  try: 
      key = some_message[0]
  except:
      key = None
  msg = json.dumps(some_message)
  res = producer.send(some_topic, value=msg, key=key)
  </code></pre>
  
  <p>However, with this code, <em>no</em> messages ever make it out of the program to the broker. I've verified that the key value extracted from <code>some_message</code> is always a valid string. Presumably I don't need to define my own <code>partitioner</code>, since, according to the documentation:</p>
  
  <blockquote>
    <p>The default partitioner implementation hashes each non-None key using the same murmur2 algorithm as the java client so that messages with the same key are assigned to the same partition.</p>
  </blockquote>
  
  <p>Furthermore, with the new code, when I try to determine what happened to my <code>send</code> by calling <code>res.get</code> (to obtain a <code>kafka.FutureRecordMetadata</code>), <em>that</em> call throws a <code>TypeError</code> exception with the message <code>descriptor 'encode' requires a 'str' object but received a 'unicode'</code>.</p>
  
  <p>(As a side question, I'm not exactly sure what I'd do with the <code>FutureRecordMetadata</code> if I were actually able to get it. Based on the kafka-python source code, I assume I'd want to call either its <code>succeeded</code> or its <code>failed</code> method, but the documentation is silent on the point. The documentation <em>does</em> say that the return value of <code>send</code> "resolves to" <code>RecordMetadata</code>, but I haven't been able to figure out, from either the documentation or the code, what "resolves to" means in this context.)</p>
  
  <p>Anyway: I can't be the only person using kafka-python 1.3.3 who's ever tried to send messages with a partitioning key, and I have not seen anything on teh Intertubes describing a similar problem (except for the SO question I referenced at the top of this post).</p>
  
  <p>I'm certainly willing to believe that I'm doing something wrong, but I have no idea what that might be. Is there some additional parameter I need to supply to the <code>KafkaProducer</code> constructor?</p>