gpt4 book ai didi

python - 类型错误 : __init__() takes exactly 1 argument (2 given)

转载 作者:行者123 更新时间:2023-12-04 18:41:02 25 4
gpt4 key购买 nike

我正在尝试在 ubuntu 中运行 monasca-persister 组件,但是与 kafka 相关的文件出现错误,我的 kafka 服务器运行良好。

Process Process-2:
commit_timeout=kafka_conf.max_wait_time_seconds)
File "/usr/local/lib/python2.7/dist-packages/monasca_common/kafka/consumer.py", line 92, in __init__
Traceback (most recent call last):
self._kafka = kafka.client.KafkaClient(kafka_url)
TypeError: __init__() takes exactly 1 argument (2 given)
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "persister.py", line 126, in start_process
persister = Persister(kafka_config, cfg.CONF.zookeeper, respository)
File "/home/dpeuser/monasca-persister/monasca_persister/repositories/persister.py", line 42, in __init__
commit_timeout=kafka_conf.max_wait_time_seconds)
File "/usr/local/lib/python2.7/dist-packages/monasca_common/kafka/consumer.py", line 92, in __init__
self._kafka = kafka.client.KafkaClient(kafka_url)
TypeError: __init__() takes exactly 1 argument (2 given)
2016-08-31 12:05:55.245 28419 INFO __main__ [-] Received signal 17, beginning graceful shutdown.

所以,我检查了错误的文件,但我不知道出了什么问题
class KafkaConsumer(object):
def __init__(self, kafka_url,
zookeeper_url, zookeeper_path,
group, topic,
fetch_size=1048576,
repartition_callback=None,
commit_callback=None,
commit_timeout=30):
"""Init
kafka_url - Kafka location
zookeeper_url - Zookeeper location
zookeeper_path - Zookeeper path used for partition
negotiation
group - Kafka consumer group
topic - Kafka topic
repartition_callback - Callback to run when the Kafka consumer
group changes. Repartitioning takes a
relatively long time so this is a good
time to flush and commit any data.
commit_callback - Callback to run when the commit_timeout
has elapsed between commits.
commit_timeout - Timeout between commits.
"""

self._kazoo_client = None
self._set_partitioner = None

self._repartition_callback = repartition_callback

self._commit_callback = commit_callback
self._commit_timeout = commit_timeout

self._last_commit = 0

self._partitions = []

self._kafka_group = group
self._kafka_topic = topic
self._kafka_fetch_size = fetch_size

self._zookeeper_url = zookeeper_url
self._zookeeper_path = zookeeper_path

self._kafka = kafka.client.KafkaClient(kafka_url)

self._consumer = self._create_kafka_consumer()

最佳答案

KafkaClient类不接受任何位置参数。将配置作为关键字参数传入:

self._kafka = kafka.client.KafkaClient(bootstrap_servers=kafka_url)

source linked from the documentation查看接受哪些配置关键字以及它们的默认值是什么。 KafkaConsumer class 也记录了许多相同的配置选项。 .

关于python - 类型错误 : __init__() takes exactly 1 argument (2 given),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39254432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com