SyntaxError on "self.async" when running python kafka producer
Asked Answered
M

1

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

Mighty answered 20/1, 2021 at 12:21 Comment(3)
Can you share the code snippetGussie
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 issueMighty
async is a reserved word. docs.python.org/3/reference/….Shulem
L
121

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

Linalool answered 26/1, 2021 at 20:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.