运行python kafka生产者时“self.async”上的SyntaxError

问题描述

$ docker run 34a24a8a745e
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

我曾看到过一个相同的错误,但我使用的是 from kafka import KafkaProducer

我的新 python 脚本使用 from kafka.producer import KafkaProducer,但我仍然收到 self.async 错误

解决方法

您需要安装 kafka-python,而不是 kafka 软件包

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