splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

csv.Dialect parameters(delimiter, quotechar, lineterminator) cannot be in bytes format.

Open bj8798 opened this issue 7 years ago • 4 comments

I faced this issue while using splunklib on python 3. version: 1.6.6 platform: Linux(centos) framework version: Python 3.7.2 Splunk version: 8.0.0 (build: 7f1fa0caa96a)(beta build for testing)

Following is the trace of error.

2019-07-03 14:25:39,156, Level=ERROR, Pid=2240, File=search_command.py, Line=981, TypeError at "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/splunklib/searchcommands/validators.py", line 270 : "delimiter" must be string, not bytes Traceback: File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/splunklib/searchcommands/search_command.py", line 603, in _process_protocol_v1 self._execute(ifile, None) File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/splunklib/searchcommands/generating_command.py", line 208, in _execute self._record_writer.write_records(self.generate()) File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/splunklib/searchcommands/internals.py", line 521, in write_records for record in records: File "/opt/splunk/etc/apps/SA-ldapsearch/bin/ldaptestconnection.py", line 53, in generate configuration = app.Configuration(self) File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/app/configuration.py", line 54, in init self._read_configuration() File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/app/configuration.py", line 447, in _read_configuration self._reset_fields(command.domain, settings) File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/app/configuration.py", line 480, in _reset_fields host = self._get_value(settings, 'server', require=True, validate=List()) File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/app/configuration.py", line 398, in _get_value value = validate(value) File "/opt/splunk/etc/apps/SA-ldapsearch/bin/packages/splunklib/searchcommands/validators.py", line 270, in call value = next(csv.reader([value], self.Dialect))

I looked into it, I think that below code snippet is causing this issue:

class Dialect(csv.Dialect):
    """ Describes the properties of list option values. """
    strict = True
    delimiter = b','
    quotechar = b'"'
    doublequote = True
    lineterminator = b'\n'
    skipinitialspace = True
    quoting = csv.QUOTE_MINIMAL

I changed it to a below code to make it work. Is it okay to make the following change or there is more change required?

class Dialect(csv.Dialect):
    """ Describes the properties of list option values. """
    strict = True
    delimiter = ','
    quotechar = '"'
    doublequote = True
    lineterminator = '\n'
    skipinitialspace = True
    quoting = csv.QUOTE_MINIMAL

bj8798 avatar Jul 05 '19 09:07 bj8798

@bj8798 thanks for reporting the bug, can you try upgrading to the latest SDK?

shakeelmohamed avatar Jul 08 '19 21:07 shakeelmohamed

@bj8798 what version of SA-ldapsearch are you using?

xuchen509 avatar Jul 30 '19 18:07 xuchen509

Hi @xuchen509, we are currently working on the migration of SA-ldapsearch v2.2.1 to python 3. For that, we have updated the splunklib(used in SA-ldapsearch) with the latest version(v1.6.6) and facing this issue.

bj8798 avatar Jul 30 '19 18:07 bj8798

fixed in https://github.com/splunk/splunk-sdk-python/pull/259. Thank you!

xuchen509 avatar Aug 01 '19 17:08 xuchen509