<?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: In Splunk Enterprise, can you help me call an external Python3 via Script? in Installation</title>
    <link>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397732#M8188</link>
    <description>&lt;P&gt;There's a new app called &lt;A href="https://splunkbase.splunk.com/app/4322"&gt;PyDen&lt;/A&gt; which would allow for an alternative approach to this problem. The app allows a developer to create Python virtual environments of any version (2.7, 3.5+) for use by scripts run by Splunk. This would allow you to do simply use the Python 3 script you've written as the input script instead of using a wrapper. &lt;/P&gt;</description>
    <pubDate>Sun, 30 Dec 2018 04:59:47 GMT</pubDate>
    <dc:creator>badarsebard</dc:creator>
    <dc:date>2018-12-30T04:59:47Z</dc:date>
    <item>
      <title>In Splunk Enterprise, can you help me call an external Python3 via Script?</title>
      <link>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397730#M8186</link>
      <description>&lt;P&gt;Splunk still uses Python 2.7 internally but has the ability to call external scripts to generate data via &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.3/AdvancedDev/ScriptedInputsIntro"&gt;Scripted Inputs&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I would like to pull data using an external API which has a Python 3 library. I have installed Python 3 to a separate place on the file system and written a Windows batch script, which calls this and invokes the Python 3 API. When run from the OS, this generates the data I would like, but if I try to add this batch script as an input to Splunk, I get an error along the lines of the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ERROR ExecProcessor - message from "e:\splunk\bin\scripts\test.bat" Fatal Python error: Py_Initialize: unable to load the file system codec 
ERROR ExecProcessor - message from "e:\splunk\bin\scripts\test.bat" File "E:\splunk\Python-2.7\Lib\encodings\__init__.py", line 123 
ERROR ExecProcessor - message from "e:\splunk\bin\scripts\test.bat" raise CodecRegistryError,\ 
ERROR ExecProcessor - message from "e:\splunk\bin\scripts\test.bat" ^ 
ERROR ExecProcessor - message from "e:\splunk\bin\scripts\test.bat" SyntaxError: invalid syntax 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get a similar error even if I minimally set the batch script to only contain a minimal statement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;path to python3&amp;gt;\python.exe -c 'print("Hello")' 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This implies the problem is something from Python 2 being passed to the Python 3 environment since the Splunk script call is ultimately from that.&lt;/P&gt;

&lt;P&gt;I asked Splunk support about this and was told it "isn't supported" and was directed to contact professional services which seems like overkill for what is likely just an environment issue.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Is there a way to wrap the python commands such that this still works?&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;As of now my workaround is to have the batch file called as a scheduled task in Windows and write the results to a file which is then monitored by Splunk. Additionally, at some point Splunk will make the jump internally to Python 3 and likely people will have the reverse problem with older Python 2.X libraries.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 18:38:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397730#M8186</guid>
      <dc:creator>blangrill</dc:creator>
      <dc:date>2018-10-02T18:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: In Splunk Enterprise, can you help me call an external Python3 via Script?</title>
      <link>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397731#M8187</link>
      <description>&lt;P&gt;The answer is quite simple. Adding -E to the Python3 call tells it to ignore other PYTHONPATH variables and it is able to run successfully.&lt;/P&gt;

&lt;P&gt;The batch file I am calling as a Splunk scripted input now looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;@ECHO off
C:\Python37\python.exe -E "&amp;lt;path to python3 script&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Oct 2018 14:41:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397731#M8187</guid>
      <dc:creator>blangrill</dc:creator>
      <dc:date>2018-10-10T14:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: In Splunk Enterprise, can you help me call an external Python3 via Script?</title>
      <link>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397732#M8188</link>
      <description>&lt;P&gt;There's a new app called &lt;A href="https://splunkbase.splunk.com/app/4322"&gt;PyDen&lt;/A&gt; which would allow for an alternative approach to this problem. The app allows a developer to create Python virtual environments of any version (2.7, 3.5+) for use by scripts run by Splunk. This would allow you to do simply use the Python 3 script you've written as the input script instead of using a wrapper. &lt;/P&gt;</description>
      <pubDate>Sun, 30 Dec 2018 04:59:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Installation/In-Splunk-Enterprise-can-you-help-me-call-an-external-Python3/m-p/397732#M8188</guid>
      <dc:creator>badarsebard</dc:creator>
      <dc:date>2018-12-30T04:59:47Z</dc:date>
    </item>
  </channel>
</rss>

