How to Solve NameError: name 'KafkaProducer' is not defined -- kafka

Solution: Import the 'KafkaProducer' module

To Solve the error, add the following line to the top of your code.

from kafka import KafkaProducer

 

For more information:
Python kafka KafkaProducer