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

ResultsReader - Unable to display results. AttributeError: itertext

Open amith-reddy opened this issue 11 years ago • 3 comments

I am getting following error while displaying results of a search command. Python version: 2.6.6 splunk-sdk==1.3.1

Error:

[[email protected] commands]$ ./splunksdk.py Wait for the search to finish... ...done!

Search job properties Search job ID: 1426098588.649812.splunk15.ops.expertcity.com The number of events: 1048236 The number of results: 3 Search duration: 16.927000 seconds This job expires in: 600 seconds Search results:

Traceback (most recent call last): File "./splunksdk.py", line 44, in for result in results.ResultsReader(response): File "/usr/lib/python2.6/site-packages/splunklib/results.py", line 205, in next return self._gen.next() File "/usr/lib/python2.6/site-packages/splunklib/results.py", line 249, in _parse_results text = "".join(elem.itertext()) AttributeError: itertext

Code:

!/usr/bin/python -u

import splunklib.client as client import splunklib.results as results from time import sleep import sys

service = client.connect( host=HOST, port=PORT, username=USERNAME, password=PASSWORD)

jobs = service.jobs

kwargs_blockingsearch = {"exec_mode": "blocking","earliest_time":'-1h'} searchquery_blocking = "search index=_internal source=*license_usage.log type=Usage |eval GB=b/1024/1024/1024 |eval PZGB=poolsz/1024/1024/1024| chart sum(GB) as UsageGB by pool"

print "Wait for the search to finish..."

job = jobs.create(searchquery_blocking, **kwargs_blockingsearch) print "...done!\n"

print "Search job properties" print "Search job ID: ", job["sid"] print "The number of events: ", job["eventCount"] print "The number of results:", job["resultCount"] print "Search duration: ", job["runDuration"], "seconds" print "This job expires in: ", job["ttl"], "seconds"

print "Search results:\n"

response = job.results() for result in results.ResultsReader(response): print result

amith-reddy avatar Mar 11 '15 19:03 amith-reddy

Hi @amith-reddy,

We've fixed this on the develop branch, see the commit here: https://github.com/splunk/splunk-sdk-python/commit/867dd46486fa2283a9f6a4c7b750808685dba49f

Your choices at this time are:

  • clone the develop branch (and potentially encounter more bugs)
  • use v1.2.3 of the SDK
  • use Python 2.7.x

Hopefully that helps!

shakeelmohamed avatar Mar 11 '15 19:03 shakeelmohamed

I used SDK version 1.2.3 to resolve the issue. Thanks for the quick support.

amith-reddy avatar Mar 11 '15 20:03 amith-reddy

Hi @amith-reddy we've just released v1.4.0 that addresses this.

shakeelmohamed avatar Aug 05 '15 00:08 shakeelmohamed