TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given
Hello,
I had a custom search command working with the python2 version of splunklib. I moved now to python3 and I have this error:
01-20-2023 16:07:54.435 INFO ChunkedExternProcessor - Running process: /opt/splunk/bin/python3.7 /opt/splunk/etc/apps/cdc_ipam_exp/bin/ipamextr.py
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: Traceback (most recent call last):
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: File "/opt/splunk/etc/apps/cdc_ipam_exp/bin/ipamextr.py", line 11, in <module>
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: from splunklib.searchcommands import \
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: File "/opt/splunk/etc/apps/cdc_ipam_exp/bin/../lib/splunklib/searchcommands/__init__.py", line 149, in <module>
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: from .environment import *
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: File "/opt/splunk/etc/apps/cdc_ipam_exp/bin/../lib/splunklib/searchcommands/environment.py", line 120, in <module>
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: splunklib_logger, logging_configuration = configure_logging('splunklib')
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: File "/opt/splunk/etc/apps/cdc_ipam_exp/bin/../lib/splunklib/searchcommands/environment.py", line 103, in configure_logging
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: fileConfig(filename, {'SPLUNK_HOME': splunk_home})
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: File "/opt/splunk/lib/python3.7/logging/config.py", line 79, in fileConfig
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: handlers = _install_handlers(cp, formatters)
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: File "/opt/splunk/lib/python3.7/logging/config.py", line 145, in _install_handlers
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: h = klass(*args, **kwargs)
01-20-2023 16:07:54.530 ERROR ChunkedExternProcessor - stderr: TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given
I'm running Splunk 8.1.12 (under Linux) and I am using the latest SDK 1.7.2 My env python is 3.8
The script I am using is:
#!/usr/bin/env python
import sys,os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
import time
import csv
from ipaddress import ip_address, IPv4Network
from ipam_api import API as IpamApi
from splunklib.searchcommands import \
dispatch, GeneratingCommand, Configuration, Option, validators
@Configuration()
class IPAMExtrCommand(GeneratingCommand):
def generate(self):
api = IpamApi("https://ipam3/")
views = api.get_view_list()
for view in views:
nv = view['name']
if nv != 'default':
with api.csv_export('network', network_view=nv, stream=True) as r:
f = (line.decode('utf-8') for line in r.iter_lines())
reader = csv.DictReader(f)
prefix = reader.fieldnames[0]
for row in reader:
dictout = { '_time': time.strftime("%Y-%m-%d") }
if not 'address*' in row.keys():
continue
del row[prefix]
cidr_i= IPv4Network(row['address*']+'/'+row['netmask*']).prefixlen
net32= { 'network_32': int(ip_address(row['address*'])) }
cidr= { 'cidr': cidr_i }
subnet= { 'subnet': row['address*']+ '/' + str(cidr_i) }
dictout.update(row)
dictout.update(net32)
dictout.update(subnet)
dictout.update(cidr)
yield dictout
dispatch(IPAMExtrCommand, sys.argv, sys.stdin, sys.stdout, __name__)
Please can you help me to fix this?
thanks, Fausto
Hi @TheFausap , We have tried to reproduce issue on our end with similar environment setup (without ipam_api package), and code is working fine without any error. As we don't have access to the ipam_api package requesting you to share how we can install the package, so we can reproduce the issue.
Hi @akaila-splunk, yesterday I found the cause for this error. In my logging.conf I had an entry for "splunklib". That logging.conf was working in the past, with an older splunklib SDK. So I removed the entries below and the error disappeared.
[logger_splunklib]
qualname = splunklib
level = NOTSET
handlers = splunklib
propagate = 0
[handler_splunklib]
# Select this handler to log events to $SPLUNK_HOME/var/log/splunk/splunklib.log
class = logging.handlers.RotatingFileHandler
args = ('/opt/splunk/var/log/splunk/splunklib.log', 'a', 524288000, 9, 'utf-8', True)
level = NOTSET
formatter = searchcommands