<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to output raw results from the Splunk Python SDK when using pagination? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-output-raw-results-from-the-Splunk-Python-SDK-when-using/m-p/255706#M3191</link>
    <description>&lt;P&gt;So I was having the same problem as here:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/99633/only-100-results-return-with-python-api-query.html"&gt;https://answers.splunk.com/answers/99633/only-100-results-return-with-python-api-query.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;and I used this: &lt;A href="http://dev.splunk.com/view/SP-CAAAEE5#paginating"&gt;http://dev.splunk.com/view/SP-CAAAEE5#paginating&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
and this: &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAER5"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAER5&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;To create a script that now returns ALL my results, BUT I need to write the raw results to a file.&lt;/P&gt;

&lt;P&gt;I WAS using the following syntax:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;snip&amp;gt;
kwargs_normalsearch = {"exec_mode":"normal"}
job = service.jobs.create(searchquery, **kwargs_normalsearch)

&amp;lt;check for job to be done&amp;gt;

content = str(job.results(output_mode="raw"))
file.write(content)
&amp;lt;snip&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I have not figured out how to combine the output_mode="raw" into the pagination script.  I have not yet found anything in the above documentation or via Google showing the correct syntax, so I'm asking here.&lt;/P&gt;

&lt;P&gt;I basically copied what was on one of the pages listed above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;kwargs_blockingsearch = {"exec_mode":"blocking"}

print "Search results:\n"
resultCount = job["resultCount"]  # Number of results this job returned
offset = 0;                       # Start at result 0
count = 10;                       # Get sets of 10 results at a time

while (offset &amp;lt; int(resultCount)):
    kwargs_paginate = {"count": count, "offset": offset}

    # Get the search results and display them
    blocksearch_results = job.results(**kwargs_paginate)

    for result in results.ResultsReader(blocksearch_results):
        print result

    # Increase the offset to get the next set of results
    offset += count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I've tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;blocksearch_results = job.results(**kwargs_paginate, output_mode="raw")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;blocksearch_results = str(job.results(**kwargs_paginate, output_mode="raw"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;kwargs_paginate = {'output_mode": "raw", "count": count, "offset": offset}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;all fail due to invalid syntax.&lt;/P&gt;

&lt;P&gt;Does anyone have any suggestions?&lt;/P&gt;</description>
    <pubDate>Wed, 31 Aug 2016 17:03:52 GMT</pubDate>
    <dc:creator>reswob4</dc:creator>
    <dc:date>2016-08-31T17:03:52Z</dc:date>
    <item>
      <title>How to output raw results from the Splunk Python SDK when using pagination?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-output-raw-results-from-the-Splunk-Python-SDK-when-using/m-p/255706#M3191</link>
      <description>&lt;P&gt;So I was having the same problem as here:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/99633/only-100-results-return-with-python-api-query.html"&gt;https://answers.splunk.com/answers/99633/only-100-results-return-with-python-api-query.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;and I used this: &lt;A href="http://dev.splunk.com/view/SP-CAAAEE5#paginating"&gt;http://dev.splunk.com/view/SP-CAAAEE5#paginating&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
and this: &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAER5"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAER5&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;To create a script that now returns ALL my results, BUT I need to write the raw results to a file.&lt;/P&gt;

&lt;P&gt;I WAS using the following syntax:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;snip&amp;gt;
kwargs_normalsearch = {"exec_mode":"normal"}
job = service.jobs.create(searchquery, **kwargs_normalsearch)

&amp;lt;check for job to be done&amp;gt;

content = str(job.results(output_mode="raw"))
file.write(content)
&amp;lt;snip&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I have not figured out how to combine the output_mode="raw" into the pagination script.  I have not yet found anything in the above documentation or via Google showing the correct syntax, so I'm asking here.&lt;/P&gt;

&lt;P&gt;I basically copied what was on one of the pages listed above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;kwargs_blockingsearch = {"exec_mode":"blocking"}

print "Search results:\n"
resultCount = job["resultCount"]  # Number of results this job returned
offset = 0;                       # Start at result 0
count = 10;                       # Get sets of 10 results at a time

while (offset &amp;lt; int(resultCount)):
    kwargs_paginate = {"count": count, "offset": offset}

    # Get the search results and display them
    blocksearch_results = job.results(**kwargs_paginate)

    for result in results.ResultsReader(blocksearch_results):
        print result

    # Increase the offset to get the next set of results
    offset += count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I've tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;blocksearch_results = job.results(**kwargs_paginate, output_mode="raw")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;blocksearch_results = str(job.results(**kwargs_paginate, output_mode="raw"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;kwargs_paginate = {'output_mode": "raw", "count": count, "offset": offset}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;all fail due to invalid syntax.&lt;/P&gt;

&lt;P&gt;Does anyone have any suggestions?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 17:03:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-output-raw-results-from-the-Splunk-Python-SDK-when-using/m-p/255706#M3191</guid>
      <dc:creator>reswob4</dc:creator>
      <dc:date>2016-08-31T17:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to output raw results from the Splunk Python SDK when using pagination?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-output-raw-results-from-the-Splunk-Python-SDK-when-using/m-p/255707#M3192</link>
      <description>&lt;P&gt;I figured it out.&lt;/P&gt;

&lt;P&gt;Once I realized the results are returned in ordered dictionaries, here's what i did:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    searchquery = "search &amp;lt;your search query&amp;gt; | table _raw"
.....
.....
    for result in results.ResultsReader(blocksearch_results):
          event=result.popitem()
          print event[1]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns only the _raw results for each.  I'm writing them to a file &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;f.write(event[1] + "\n")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;do with them what you will.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 14:12:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-output-raw-results-from-the-Splunk-Python-SDK-when-using/m-p/255707#M3192</guid>
      <dc:creator>reswob4</dc:creator>
      <dc:date>2016-09-06T14:12:37Z</dc:date>
    </item>
  </channel>
</rss>

