title: How to publish dictionary in Kafka?
body: <p>I am trying to publish a response in a kafka topic. This response is fetched from a mongodb.</p>
  
  <pre><code>from kafka import KafkaProducer
  from kafka.errors import KafkaError
  import json
  import pymongo
  from pymongo import MongoClient
  import sys
  import datetime
  
  try:
      client = MongoClient('mongodb://A.B.C.D:27017/prod-production')
      db = client["prod-production"]
  except Exception as e:
      print("Error occurred while connecting to DB")
      print(e)
  producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
  producer = KafkaProducer(retries=5)
  print("Initial time:")
  print(datetime.datetime.now())
  count = 1
  for response in db.Response.find():
      if count &gt;= 20:
          producer.flush()
          sys.exit()
      count += 1
      print(count)
      producer.send('example-topic', bytes(response))
  print("Final time")
  print(datetime.datetime.now())
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):   File "producer.py", line 28, in &lt;module&gt;
      producer.send('collect-production-response', bytes(response)) TypeError: 'str' object cannot be interpreted as an integer
  </code></pre>
  
  <p>However, in python2, this error does not occur.</p>