<?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: External python search - Error &amp;quot;Failed to parse transport header&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/588501#M204971</link>
    <description>&lt;P&gt;I solved it! The solution reflects SO poorly on Splunk.&lt;/P&gt;&lt;P&gt;I ran my command with "--debug" and got this output:&lt;/P&gt;&lt;PRE&gt;Command list_entities appears to be statically configured for search command protocol version 1 and static configuration is unsupported by splunklib.searchcommands. Please ensure that default/commands.conf contains this stanza: [generatetext] filename = generatetext.py enableheader = true outputheader = true requires_srinfo = true supports_getinfo = true&lt;/PRE&gt;&lt;P&gt;If you add those settings to your commands.conf it should work&lt;/P&gt;&lt;P&gt;Splunk's OWN DOCS AND EXAMPLES IN MULTIPLE PLACES say "chunked = true" specifies search command protocol version 2&lt;/P&gt;&lt;P&gt;Like here&amp;nbsp;&lt;A href="https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/createcustomsearchcmd#Register-your-custom-search-command" target="_blank" rel="noopener"&gt;https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/createcustomsearchcmd#Register-your-custom-search-command&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And here&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/ITSI/4.12.0/Configure/commands.conf" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/ITSI/4.12.0/Configure/commands.conf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And here&amp;nbsp;&lt;A href="https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/default/commands.conf" target="_blank" rel="noopener"&gt;https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/default/commands.conf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Wow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2022 01:13:05 GMT</pubDate>
    <dc:creator>bpna</dc:creator>
    <dc:date>2022-03-11T01:13:05Z</dc:date>
    <item>
      <title>External python search - How do I resolve Error "Failed to parse transport header"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/555741#M157770</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I'm trying to write a very simple external python search but it's just not working.&lt;/P&gt;&lt;P&gt;I get the following error message in search_messages.log:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;06-15-2021 09:44:22.543 +0200 ERROR SearchMessages - orig_component="script" app="search" sid="1623743052.198909" message_key="EXTERN:SCRIPT_NONZERO_RETURN" message=External search command 'pyTest' returned error code 1. Script output = "chunked 1.0,241,0\n{"inspector":{"messages":[["ERROR","RuntimeError at \"D:\\Splunk\\etc\\apps\\pyTest\\bin\\splunklib\\searchcommands\\search_command.py\", line 884 : Failed to parse transport header: b'splunkVersion:8.2.0\\n'"]]},"finished":true}".&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It says message_key="EXTERN:SCRIPT_NONZERO_RETURN" and "Failed to parse transport header".&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is how I call the script in a splunk search:&lt;/P&gt;&lt;P&gt;| makeresults 1 | eval something="just_a_value" | script pyTest&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;| script pyTest&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my commands.conf:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[pyTest]
python.version = python3
chunked = true
filename = pyTest.py&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/python3
import os, sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
import splunk.Intersplunk
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration

@Configuration()
class pyTest(StreamingCommand):
    def stream(self, events):
        for event in events:
            event['nothing'] = 'world'
            yield event

dispatch(pyTest, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried to replace \r\n with \n in the code but that didn't help. What am I doing wrong here?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 15:22:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/555741#M157770</guid>
      <dc:creator>kepffr</dc:creator>
      <dc:date>2022-08-02T15:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: External python search - Error "Failed to parse transport header"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/556126#M157912</link>
      <description>&lt;P&gt;Hi guys. Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 07:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/556126#M157912</guid>
      <dc:creator>kepffr</dc:creator>
      <dc:date>2021-06-17T07:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: External python search - Error "Failed to parse transport header"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/588498#M204969</link>
      <description>&lt;P&gt;I'm having the same issue.&lt;/P&gt;&lt;P&gt;Actually after pulling my hair out over it, copied the generatetext command example from Splunk SDK for Python GitHub repo into my instance&amp;nbsp;&lt;A href="https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/bin/generatetext.py" target="_blank"&gt;https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/bin/generatetext.py&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Copied default/commands.conf. Setup splunklib directory.&lt;/P&gt;&lt;P&gt;Splunk v8.2.2, should play nicely with python3&lt;/P&gt;&lt;P&gt;Still failing with this error. Did you ever solve it?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 00:15:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/588498#M204969</guid>
      <dc:creator>bpna</dc:creator>
      <dc:date>2022-03-11T00:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: External python search - Error "Failed to parse transport header"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/588501#M204971</link>
      <description>&lt;P&gt;I solved it! The solution reflects SO poorly on Splunk.&lt;/P&gt;&lt;P&gt;I ran my command with "--debug" and got this output:&lt;/P&gt;&lt;PRE&gt;Command list_entities appears to be statically configured for search command protocol version 1 and static configuration is unsupported by splunklib.searchcommands. Please ensure that default/commands.conf contains this stanza: [generatetext] filename = generatetext.py enableheader = true outputheader = true requires_srinfo = true supports_getinfo = true&lt;/PRE&gt;&lt;P&gt;If you add those settings to your commands.conf it should work&lt;/P&gt;&lt;P&gt;Splunk's OWN DOCS AND EXAMPLES IN MULTIPLE PLACES say "chunked = true" specifies search command protocol version 2&lt;/P&gt;&lt;P&gt;Like here&amp;nbsp;&lt;A href="https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/createcustomsearchcmd#Register-your-custom-search-command" target="_blank" rel="noopener"&gt;https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/createcustomsearchcmd#Register-your-custom-search-command&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And here&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/ITSI/4.12.0/Configure/commands.conf" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/ITSI/4.12.0/Configure/commands.conf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And here&amp;nbsp;&lt;A href="https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/default/commands.conf" target="_blank" rel="noopener"&gt;https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/default/commands.conf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Wow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 01:13:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/588501#M204971</guid>
      <dc:creator>bpna</dc:creator>
      <dc:date>2022-03-11T01:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: External python search - Error "Failed to parse transport header"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/607944#M211387</link>
      <description>&lt;P&gt;FWIW, I had this same problem and fixed it by changing my OS command from subprocess.run() to subprocess.Popen.&amp;nbsp; Not sure why, but it seem's Splunk's implementation of Python 3.7 has issues with subprocess.run() and streaming commands.&lt;BR /&gt;&lt;BR /&gt;This allowed me to use&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;chunked = true&lt;/LI-CODE&gt;&lt;P&gt;without any problems.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 15:21:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/607944#M211387</guid>
      <dc:creator>ohbuckeyeio</dc:creator>
      <dc:date>2022-08-02T15:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: External python search - Error "Failed to parse transport header"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/607948#M211388</link>
      <description>&lt;P&gt;That's interesting, thanks for the info. Helpful to know it's an issue with Splunk's usage of python internally.&lt;/P&gt;&lt;P&gt;I was able to solve it by editing commands.conf to the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[list_entities]
filename = list_entities.py
enableheader = true
outputheader = true
requires_srinfo = true
supports_getinfo = true
supports_multivalues = true
supports_rawargs = true
python.version = python3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 16:02:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/607948#M211388</guid>
      <dc:creator>bpna</dc:creator>
      <dc:date>2022-08-02T16:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: External python search - Error "Failed to parse transport header"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/651090#M225111</link>
      <description>&lt;P&gt;Thank you! Worked OK!&lt;/P&gt;&lt;P&gt;I faced the same error. You helped a lot! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 08:13:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-python-search-How-do-I-resolve-Error-quot-Failed-to/m-p/651090#M225111</guid>
      <dc:creator>highsplunker</dc:creator>
      <dc:date>2023-07-19T08:13:33Z</dc:date>
    </item>
  </channel>
</rss>

