3

I am working with ceilometer python API and publishing data to pubnub. not sure what is meant by this error.

This is the part of code that is causing the problem i think,

def init_Data(data, channel):
  cpu_sample = cclient.samples.list(meter_name ='cpu_util')
  for each in cpu_sample:
    timetamp = each.timestamp
    volume =  each.counter_volume
    volume_int = int(volume)
    data_volume ={'value': volume_int}
    data=json.dumps(data_volume)
    print (data)


pubnub.publish(channel='orbit_channel', callback= init_Datar)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
Imo
  • 1,455
  • 4
  • 28
  • 53

2 Answers2

5

publish() takes at least 3 arguments (3 given)

Such a terrible error message! One point of confusion is that self is also counted as an argument, even if it's not explicitly provided.

So you need to provide 2 arguments. And you did! But you need to provide the 2 required arguments, while you only provided 1 required and 1 optional argument. Check the API docs for pubnub.publish() to see what you're missing.

user2357112
  • 260,549
  • 28
  • 431
  • 505
Daniel Darabos
  • 26,991
  • 10
  • 102
  • 114
  • 1
    Thank you for your answer. This makes things clear but at API docs for pubnub the function is constructed with 2 kayword arguments. http://www.pubnub.com/docs/python/data-streams-publish-and-subscribe – Imo Jun 30 '15 at 12:07
  • 1
    You can provide the positional arguments via keywords too, but you _must_ provide them somehow. You're not providing the second positional argument, which is `message`. – Daniel Darabos Jun 30 '15 at 12:13
1

While Daniel provided a good explanation, I wanted a minimalist example and was able to come up with this:

>>> class Foo(object):
...     def __init__(self, arg1, arg2=None):
...         pass
... 
>>> Foo(arg2=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes at least 2 arguments (2 given)

So two arguments are provided (self and arg2), but it's saying at least 2 positional arguments are required (self and arg1). So Foo(arg1=1) would work, as would Foo(1, 2) and Foo(1, arg2=2).

Kat
  • 4,645
  • 4
  • 29
  • 81