TurboWay / spiderman

基于 scrapy-redis 的通用分布式爬虫框架
MIT License
591 stars 128 forks source link

kafka监控程序运行报错 #12

Closed zczczc2018 closed 3 years ago

zczczc2018 commented 3 years ago

Traceback (most recent call last): File "C:\Users\chengzhang\AppData\Local\Programs\Python\Python39\lib\site-packages\kafka\consumer\fetcher.py", line 445, in _message_generator raise StopIteration('Subscription needs partition assignment') StopIteration: Subscription needs partition assignment

是consumer.subscribe()需要别的参数吗,我看运行实例图片上也只有topics=['zhifang',]这一个参数

TurboWay commented 3 years ago

应该不需要。每个 kafka 主题都至少会有一个分区,这个看起来像是 kafka 的环境问题,可以运行下 kafka 命令,看是否可以正常消费

kafka-console-consumer --bootstrap-server your-kafka-broker:9092 --topic zhifang --from-beginning
zczczc2018 commented 3 years ago

经过调整,kafka已经可以正常生产消费消息了,但是代码运行依旧报错

image

TurboWay commented 3 years ago

更新一下 kafka-python 包试试

pip uninstall kafka
pip install kafka-python
zczczc2018 commented 3 years ago

我使用的是python3.9的环境,kafka-1.3.5的版本,重新安装以后出现了return '' % self.async的语法错误,之前我把源码里面的async全都替换为async_了,运行报错就是StopIteration: Subscription needs partition assignment

TurboWay commented 3 years ago

我使用的是python3.9的环境,kafka-1.3.5的版本,重新安装以后出现了return '' % self.async的语法错误,之前我把源码里面的async全都替换为async_了,运行报错就是StopIteration: Subscription needs partition assignment

建议按如上命令,直接升级一下 kafka-python,再进行测试

zczczc2018 commented 3 years ago

昨天kafka配置又出现了问题,改了一下,现在使用kafka-python已经可以用了,非常感谢!