kafka 异常:return ‘<SimpleProducer batch=%s>‘ % self.async ^ SyntaxError: invalid syntax
Python3.X 执行Python编写的生产者和消费者报错,报错信息如下:Traceback (most recent call last):File "mykit_kafka_producer.py", line 9, in <module>from kafka import KafkaProducerFile "/usr/local/lib/python3.7/site-pack
·
Python3.X 执行Python编写的生产者和消费者报错,报错信息如下:
Traceback (most recent call last):
File "mykit_kafka_producer.py", line 9, in <module>
from kafka import KafkaProducer
File "/usr/local/lib/python3.7/site-packages/kafka/__init__.py", line 23, in <module>
from kafka.producer import KafkaProducer
File "/usr/local/lib/python3.7/site-packages/kafka/producer/__init__.py", line 4, in <module>
from .simple import SimpleProducer
File "/usr/local/lib/python3.7/site-packages/kafka/producer/simple.py", line 54
return '<SimpleProducer batch=%s>' % self.async
^
SyntaxError: invalid syntax
原因
python3.7新增关键字:async、await;
kafka-python 用到了关键字async,由此带来兼容性问题
解决
使用Python 3.6版本即可正常运行。
注意:先安装 kafka ,然后安装 kafka-python
pip install kafka
pip install kafka-python
更多推荐
已为社区贡献7条内容
所有评论(0)