<?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 Re: Splunk Search results as CSV- python in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387634#M113067</link>
    <description>&lt;P&gt;@poorni_p,&lt;/P&gt;

&lt;P&gt;searchStatus is an html response (a byte like object) and you need to convert that to string before doing a regex search.&lt;/P&gt;

&lt;P&gt;Try adding this to your code just below the searchStatus(line 5 in your code snippet)  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    searchStatus = searchStatus.decode('utf-8')
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 Jul 2019 06:02:00 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2019-07-15T06:02:00Z</dc:date>
    <item>
      <title>Splunk Search results as CSV- python</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387633#M113066</link>
      <description>&lt;P&gt;I am trying to get the results as CSV file with the help of this page &lt;A href="https://www.splunk.com/blog/2011/08/02/splunk-rest-api-is-easy-to-use.html"&gt;https://www.splunk.com/blog/2011/08/02/splunk-rest-api-is-easy-to-use.html&lt;/A&gt;. i modified few things and  successfully getting session id and SID, but getting the below error for the "Get the search status" query.&lt;/P&gt;

&lt;P&gt;code: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    servicesSearchStatusSTR='/services/search/jobs/%s/' %sid
    isNotDone = True
    myhttp.add_credentials('username','pwd')
    while isNotDone:
        searchStatus = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + servicesSearchStatusSTR,'GET', headers={'Authorization':'Splunk %s' % sessionkey},  body=urllib.parse.urlencode({'search':searchQuery}))[1]                                                                   
        isDoneStatus = re.compile('isDone"&amp;gt;(0|1)')
        print(isDoneStatus)
        isDoneStatus =isDoneStatus.search(searchStatus).groups()[0]\
        if(isDoneStatus == '1'):
                     isNotDone = False
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;print("%s", isDoneStatus)&lt;/P&gt;

&lt;P&gt;Error: &lt;BR /&gt;
           Traceback (most recent call last):&lt;BR /&gt;
                   File "sample.py", line 46, in &lt;MODULE&gt;&lt;BR /&gt;
                   isDoneStatus =isDoneStatus.search(searchStatus).groups()[0]\&lt;BR /&gt;
         TypeError: cannot use a string pattern on a bytes-like object&lt;/MODULE&gt;&lt;/P&gt;

&lt;P&gt;Please help me to resolve this error.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2019 06:14:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387633#M113066</guid>
      <dc:creator>poorni_p</dc:creator>
      <dc:date>2019-07-14T06:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Search results as CSV- python</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387634#M113067</link>
      <description>&lt;P&gt;@poorni_p,&lt;/P&gt;

&lt;P&gt;searchStatus is an html response (a byte like object) and you need to convert that to string before doing a regex search.&lt;/P&gt;

&lt;P&gt;Try adding this to your code just below the searchStatus(line 5 in your code snippet)  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    searchStatus = searchStatus.decode('utf-8')
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jul 2019 06:02:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387634#M113067</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-07-15T06:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Search results as CSV- python</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387635#M113068</link>
      <description>&lt;P&gt;I'm not a Python expert, but from my testing on Python 2.7 I think you might just have to remove the backslash at the end of this line:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; isDoneStatus =isDoneStatus.search(searchStatus).groups()[0]\
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jul 2019 06:57:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Search-results-as-CSV-python/m-p/387635#M113068</guid>
      <dc:creator>eavent_splunk</dc:creator>
      <dc:date>2019-07-15T06:57:39Z</dc:date>
    </item>
  </channel>
</rss>

