TypeError:__ init __()只取1个参数(给定2个)

时间:2016-08-31 16:13:41

标签: python ubuntu apache-kafka

我试图在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()

1 个答案:

答案 0 :(得分:1)

KafkaClient类没有任何位置参数。将配置作为关键字参数传递

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

请参阅source linked from the documentation以了解接受的配置关键字及其默认值。许多相同的配置选项也记录在KafkaConsumer class