<?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: Why am I getting error &amp;quot;'newline' is an invalid keyword argument&amp;quot; using the CLI to run my Python script that writes a CSV file? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211519#M41636</link>
    <description>&lt;P&gt;If your problem is resolved, please accept an answer.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Aug 2016 13:10:30 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2016-08-04T13:10:30Z</dc:date>
    <item>
      <title>Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211509#M41626</link>
      <description>&lt;P&gt;I'm accessing my python script in $SPLUNK_HOME/bin via command line (in a VM) to see if the code runs correctly. Whenever I run the file outside of commandline, the code works perfectly, but when I run it in the commandline, it gives me this error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Traceback (most recent call last):
  File "demo.py", line 105, in 
    parse_cert_csv('qualys.csv')
  File "demo.py", line 82, in parse_cert_csv
    with open(FILENAME, 'w', newline='') as csvfile:
TypeError: 'newline' is an invalid keyword argument for this function
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My writing-to-file code looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;with open(FILENAME, 'w', newline='') as csvfile:
        keys = list(rows[0].keys()) #keys are the header
        dict_writer = csv.DictWriter(csvfile, fieldnames=keys)
        dict_writer.writeheader()
        dict_writer.writerows(rows)#rows is the data I want to write to the file
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does it matter that my code doesn't work in the command line? And if so, how can I fix it?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 19:52:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211509#M41626</guid>
      <dc:creator>jenniferleenyc</dc:creator>
      <dc:date>2016-08-03T19:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211510#M41627</link>
      <description>&lt;P&gt;How are you running the script on the command line?  It should be run in the Splunk environment using &lt;CODE&gt;$SPLUNK_HOME/bin/splunk cmd python demo.py &amp;lt;args&amp;gt;&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 20:01:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211510#M41627</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-03T20:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211511#M41628</link>
      <description>&lt;P&gt;I'm running it through the terminal on a VM. &lt;BR /&gt;
How do you cd into $SPLUNK_HOME/bin/splunk if splunk is a file?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 20:07:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211511#M41628</guid>
      <dc:creator>jenniferleenyc</dc:creator>
      <dc:date>2016-08-03T20:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211512#M41629</link>
      <description>&lt;P&gt;Also I moved my python script, demo.py and data file, qualys.csv (for testing purposes) to splunk/home/etc/apps/search/bin (based on this reference: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Script"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Script&lt;/A&gt;) However I'm still confused about the Splunk environment.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 20:41:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211512#M41629</guid>
      <dc:creator>jenniferleenyc</dc:creator>
      <dc:date>2016-08-03T20:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211513#M41630</link>
      <description>&lt;P&gt;Is this script something that will be run by Splunk (scripted input, modular input)?  If so, it runs in a different environment from your typical shell.  The easiest way to run in that environment from a command line is to tell Splunk to do it using the command above.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 20:48:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211513#M41630</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-03T20:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211514#M41631</link>
      <description>&lt;P&gt;The script will be run by Splunk. Would modular input suffice if I want Splunk to automatically run the data through the script file (which writes the parsed data back into the file) and input that data into Splunk Web?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 20:59:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211514#M41631</guid>
      <dc:creator>jenniferleenyc</dc:creator>
      <dc:date>2016-08-03T20:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211515#M41632</link>
      <description>&lt;P&gt;I'm still learning modular inputs, but they're very similar to scripted inputs which will do what you want.  When Splunk runs a scripted/modular input, everything the script writes to stdout will be indexed.  Of course, when run from the command line, the script's output appears on your screen.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 21:08:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211515#M41632</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-03T21:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211516#M41633</link>
      <description>&lt;P&gt;Depending on what you want to do, you should pick how input method Splunk indexes data.&lt;/P&gt;

&lt;P&gt;If you're trying to let Splunk schedule the script to run, scripted input or modular input would a good choice. Either way, your script should write data out to standard out where Splunk parse data, instead of writing a file. &lt;/P&gt;

&lt;P&gt;For comparison between Modular Input and scripted input, please visit; &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.4.2/AdvancedDev/ModInputsBasicExample"&gt;https://docs.splunk.com/Documentation/Splunk/6.4.2/AdvancedDev/ModInputsBasicExample&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For simple example for Modular Input, please visit and try the examples;&lt;BR /&gt;
&lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAER3"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAER3&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.2/AdvancedDev/ModInputsIntro"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.2/AdvancedDev/ModInputsIntro&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;To run modular input from a command line to validate if the modular input was correctly deployed, please visit the following link;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.2/AdvancedDev/ModInputsDevTools"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.2/AdvancedDev/ModInputsDevTools&lt;/A&gt;&lt;BR /&gt;
Here is a  copy of a line to run a modular input from cmd. It requires proper scheme and configuration to run it properly. First part is to parse Modular Input configuration from configuration, and pass the output to your Modular Input Script. In this example, twitter.py. In your case, it would be demo.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk cmd splunkd print-modinput-config twitter twitter://SplunkTwitter \
   | splunk cmd python $SPLUNK_HOME/etc/apps/twitter/bin/twitter.py
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Aug 2016 21:12:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211516#M41633</guid>
      <dc:creator>Masa</dc:creator>
      <dc:date>2016-08-03T21:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211517#M41634</link>
      <description>&lt;P&gt;thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211517#M41634</guid>
      <dc:creator>jenniferleenyc</dc:creator>
      <dc:date>2016-08-04T13:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211518#M41635</link>
      <description>&lt;P&gt;thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:00:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211518#M41635</guid>
      <dc:creator>jenniferleenyc</dc:creator>
      <dc:date>2016-08-04T13:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting error "'newline' is an invalid keyword argument" using the CLI to run my Python script that writes a CSV file?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211519#M41636</link>
      <description>&lt;P&gt;If your problem is resolved, please accept an answer.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:10:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-am-I-getting-error-quot-newline-is-an-invalid-keyword/m-p/211519#M41636</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-04T13:10:30Z</dc:date>
    </item>
  </channel>
</rss>

