49
Traceback (most recent call last):
  File "//producer.py", line 1, in <module>
    from kafka.producer import KafkaProducer
  File "/usr/local/lib/python3.9/site-packages/kafka/__init__.py", line 23, in <module>
    from kafka.producer import KafkaProducer
  File "/usr/local/lib/python3.9/site-packages/kafka/producer/__init__.py", line 4, in <module>
    from .simple import SimpleProducer
  File "/usr/local/lib/python3.9/site-packages/kafka/producer/simple.py", line 54
    return '<SimpleProducer batch=%s>' % self.async
                                              ^
SyntaxError: invalid syntax

I had seen an earlier error identical but I was using from kafka import KafkaProducer

My new python script uses from kafka.producer import KafkaProducerbut I still get the self.async error

3
  • Can you share the code snippet Commented Jan 20, 2021 at 12:49
  • Sorry I have since resolved I used kafka-python library instead of just kafka and updated my docker file to use latest python version which resolved the issue
    – Harvey
    Commented Jan 20, 2021 at 13:53
  • 6
    async is a reserved word. docs.python.org/3/reference/….
    – CristiFati
    Commented Jan 20, 2021 at 15:19

1 Answer 1

122

You need to install kafka-python, not kafka package. If kafka is installed, then you need to pip uninstall kafka and replace with the other

https://github.com/dpkp/kafka-python/issues/1566

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.