<?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: how to export csv with BOM ? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198360#M39323</link>
    <description>&lt;P&gt;For anyone interested in a solution for recent Splunk versions, go to the file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunkhome/lib/python2.7/site-packages/splunk/rest/__init__.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to line 648 where it says&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def readall(self, blocksize=32768):
    """
    Returns a generator reading blocks of data from the response
    until all data has been read
    """
    response = self.response
    while 1:
        data = response.read(blocksize)
        if not data:
            break
        yield data
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Change that to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def readall(self, blocksize=32768):
    """
    Returns a generator reading blocks of data from the response
    until all data has been read
    """
    response = self.response
    import codecs
    counter = 0;
    while 1:
        data = response.read(blocksize)
        if not data:
            break

        if counter == 0:
            data = "".join((codecs.BOM_UTF8, data))
            counter += 1

        yield data
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and your exports come with BOM.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2016 10:35:54 GMT</pubDate>
    <dc:creator>jeffland</dc:creator>
    <dc:date>2016-09-02T10:35:54Z</dc:date>
    <item>
      <title>how to export csv with BOM ?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198357#M39320</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a csv file encoded UTF-8 from Scheduled Search. And MS Excel couldn't read the file Because without BOM I guess. How can I export csv file with BOM ??&lt;/P&gt;

&lt;P&gt;I searched on Splunk and found this.&lt;BR /&gt;
&lt;A href="http://answers.splunk.com/answers/5610/can-the-export-function-export-csv-file-in-big5-charset" target="_blank"&gt;http://answers.splunk.com/answers/5610/can-the-export-function-export-csv-file-in-big5-charset&lt;/A&gt;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;In the file&lt;BR /&gt;
$SPLUNK_HOME/lib/python2.6/site-packages/splunk/appserver/mrsparkle/controllers/search.py&lt;BR /&gt;
go to around line 266, where the&lt;BR /&gt;
statement output = job.getFeed(asset,&lt;BR /&gt;
http_method=jobFeedRequestMethod,&lt;BR /&gt;
**kwargs) is.&lt;/P&gt;

&lt;P&gt;Add the following code after that&lt;BR /&gt;
line:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if 'isDownload' in kwargs:
    import codecs
    output = "".join((codecs.BOM_UTF8, output))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should allow the files to be read&lt;BR /&gt;
by Excel.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;But My Python version is 2.7. So the code of Search.py is different.&lt;/P&gt;

&lt;P&gt;How can I get CSV with BOM??&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;

&lt;P&gt;Sam&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:13:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198357#M39320</guid>
      <dc:creator>newsm106</dc:creator>
      <dc:date>2020-09-28T16:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to export csv with BOM ?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198358#M39321</link>
      <description>&lt;P&gt;Tried to append code after line 342 (output = job_lite.get(asset))&lt;BR /&gt;
No result. Files still exporting without BOM&lt;/P&gt;</description>
      <pubDate>Wed, 25 Feb 2015 14:17:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198358#M39321</guid>
      <dc:creator>mcseem</dc:creator>
      <dc:date>2015-02-25T14:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to export csv with BOM ?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198359#M39322</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;When I added the above mentioned code in Python 2.7 search.py, and restarted splunk, the Web service did not start at all. The command prompt was stuck at "Waiting for the web service to be available". As soon as I removed the added three lines, it started working. Could you please let me know if there is any other way of doing the same, or whether the code is placed in the correct place.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 09:41:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198359#M39322</guid>
      <dc:creator>SwatiApte</dc:creator>
      <dc:date>2015-10-13T09:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to export csv with BOM ?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198360#M39323</link>
      <description>&lt;P&gt;For anyone interested in a solution for recent Splunk versions, go to the file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunkhome/lib/python2.7/site-packages/splunk/rest/__init__.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to line 648 where it says&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def readall(self, blocksize=32768):
    """
    Returns a generator reading blocks of data from the response
    until all data has been read
    """
    response = self.response
    while 1:
        data = response.read(blocksize)
        if not data:
            break
        yield data
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Change that to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def readall(self, blocksize=32768):
    """
    Returns a generator reading blocks of data from the response
    until all data has been read
    """
    response = self.response
    import codecs
    counter = 0;
    while 1:
        data = response.read(blocksize)
        if not data:
            break

        if counter == 0:
            data = "".join((codecs.BOM_UTF8, data))
            counter += 1

        yield data
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and your exports come with BOM.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 10:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198360#M39323</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2016-09-02T10:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to export csv with BOM ?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198361#M39324</link>
      <description>&lt;P&gt;jeffland's code works perfectly for previous splunk version&lt;/P&gt;

&lt;P&gt;but in case of splunk v8.0.0,&lt;BR /&gt;
I'm afraid python 3.7 is used&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunkhome/lib/python3.7/site-packages/splunk/rest/__init__.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and raised error like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Unrecoverable error in the server.
Traceback (most recent call last):
File "/opt/splunk/lib/python3.7/site-packages/cherrypy/_cpwsgi.py", line 184, in trap
return func(*args, **kwargs)
File "/opt/splunk/lib/python3.7/site-packages/cherrypy/_cpwsgi.py", line 277, in __next__
return next(self.iter_response)
File "/opt/splunk/lib/python3.7/site-packages/cherrypy/lib/encoding.py", line 99, in encoder
for chunk in body:
File "/opt/splunk/lib/python3.7/site-packages/splunk/rest/__init__.py", line 716, in readall
data = "".join((codecs.BOM_UTF8, data))
TypeError: sequence item 0: expected str instance, bytes found
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can I have code for python3.7?&lt;/P&gt;

&lt;P&gt;Best regards,&lt;BR /&gt;
Kang&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 01:34:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198361#M39324</guid>
      <dc:creator>ktc78</dc:creator>
      <dc:date>2019-11-07T01:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to export csv with BOM ?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198362#M39325</link>
      <description>&lt;P&gt;hey, Kang&lt;/P&gt;

&lt;P&gt;[python 2.7]&lt;BR /&gt;
data = "".join((codecs.BOM_UTF8, data)) &lt;/P&gt;

&lt;P&gt;[python 3.7]&lt;BR /&gt;
: Add 'b' in front.&lt;/P&gt;

&lt;P&gt;data = b"".join((codecs.BOM_UTF8, data))&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 01:39:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-export-csv-with-BOM/m-p/198362#M39325</guid>
      <dc:creator>kichonei</dc:creator>
      <dc:date>2020-04-21T01:39:41Z</dc:date>
    </item>
  </channel>
</rss>

