<?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 Requests.Post CSV File contents into Splunk using HEC in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Requests-Post-CSV-File-contents-into-Splunk-using-HEC/m-p/414793#M73349</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I'm having issues with using the requests library in python to send the contents of a csv file to Splunk. I've managed to do it for json files and can even convert the csv contents to a json format and post it on splunk successfully. I'm wondering if there was a way to do a requests.post and and send the csv file whilst keeping the csv format rather than changing to a json format. &lt;/P&gt;

&lt;P&gt;Here is the code I am using to post json content to splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;with open('file.csv') as f:
    reader = csv.DictReader(f)
    file_contents = list(reader)

headers = {
            'Authorization': 'Splunk 'token number''  
        }

data = {'sourcetype': '_json', 'event': file_contents}  

try:
    response = requests.post('http://localhost:8088/services/collector',
                             headers=headers, data=json.dumps(data),
                             verify=False)  
except Exception as e:
    print(str(e))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jun 2019 23:40:52 GMT</pubDate>
    <dc:creator>vkannampuzha</dc:creator>
    <dc:date>2019-06-06T23:40:52Z</dc:date>
    <item>
      <title>Requests.Post CSV File contents into Splunk using HEC</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Requests-Post-CSV-File-contents-into-Splunk-using-HEC/m-p/414793#M73349</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I'm having issues with using the requests library in python to send the contents of a csv file to Splunk. I've managed to do it for json files and can even convert the csv contents to a json format and post it on splunk successfully. I'm wondering if there was a way to do a requests.post and and send the csv file whilst keeping the csv format rather than changing to a json format. &lt;/P&gt;

&lt;P&gt;Here is the code I am using to post json content to splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;with open('file.csv') as f:
    reader = csv.DictReader(f)
    file_contents = list(reader)

headers = {
            'Authorization': 'Splunk 'token number''  
        }

data = {'sourcetype': '_json', 'event': file_contents}  

try:
    response = requests.post('http://localhost:8088/services/collector',
                             headers=headers, data=json.dumps(data),
                             verify=False)  
except Exception as e:
    print(str(e))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 23:40:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Requests-Post-CSV-File-contents-into-Splunk-using-HEC/m-p/414793#M73349</guid>
      <dc:creator>vkannampuzha</dc:creator>
      <dc:date>2019-06-06T23:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Requests.Post CSV File contents into Splunk using HEC</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Requests-Post-CSV-File-contents-into-Splunk-using-HEC/m-p/414794#M73350</link>
      <description>&lt;P&gt;After a bit of research, it turns out I can't actually send through data that has a csv format. According to the splunk documentation, I can only send through json or raw data. &lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 05:47:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Requests-Post-CSV-File-contents-into-Splunk-using-HEC/m-p/414794#M73350</guid>
      <dc:creator>vkannampuzha</dc:creator>
      <dc:date>2019-06-07T05:47:13Z</dc:date>
    </item>
  </channel>
</rss>

