<?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 Session Key Authentication fails sometimes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Session-Key-Authentication-fails-sometimes/m-p/707893#M239404</link>
    <description>&lt;P&gt;Apologies if this is in the wrong place.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im using the Splunk REST API to connect and run search requests through a Python script. I sadly don't have access to the SDK so I have to use the REST API. The issue I'm running into is that after the initial authentication and login, I get back the session key to use for subsequent API calls. The subsequent API calls have a chance to run into a 401 error more often than not, and my current working solution is to use a while loop to keep sending the information until it works. The code looks like below. I set a delay an API call happens every few seconds, but I can't figure out why it will usually fail, but then randomly choose to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;done = False
while not done:
    r = requests.post(host + '/services/search/jobs/', headers={'Authorization':'Splunk %s' %Session_key}, data={'Search':query}, verify=False)
    if r.status+code ==201:
        done = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jan 2025 18:31:51 GMT</pubDate>
    <dc:creator>Sravan2</dc:creator>
    <dc:date>2025-01-02T18:31:51Z</dc:date>
    <item>
      <title>Session Key Authentication fails sometimes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Session-Key-Authentication-fails-sometimes/m-p/707893#M239404</link>
      <description>&lt;P&gt;Apologies if this is in the wrong place.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im using the Splunk REST API to connect and run search requests through a Python script. I sadly don't have access to the SDK so I have to use the REST API. The issue I'm running into is that after the initial authentication and login, I get back the session key to use for subsequent API calls. The subsequent API calls have a chance to run into a 401 error more often than not, and my current working solution is to use a while loop to keep sending the information until it works. The code looks like below. I set a delay an API call happens every few seconds, but I can't figure out why it will usually fail, but then randomly choose to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;done = False
while not done:
    r = requests.post(host + '/services/search/jobs/', headers={'Authorization':'Splunk %s' %Session_key}, data={'Search':query}, verify=False)
    if r.status+code ==201:
        done = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 18:31:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Session-Key-Authentication-fails-sometimes/m-p/707893#M239404</guid>
      <dc:creator>Sravan2</dc:creator>
      <dc:date>2025-01-02T18:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Session Key Authentication fails sometimes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Session-Key-Authentication-fails-sometimes/m-p/707894#M239405</link>
      <description>&lt;P&gt;Is there any reason why you aren't creating a token from the interface under&amp;nbsp;Settings-&amp;gt;Users and Authentication-&amp;gt;Tokens, and then using it to call the API? That would be much more reliable than using a single session key.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 19:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Session-Key-Authentication-fails-sometimes/m-p/707894#M239405</guid>
      <dc:creator>marnall</dc:creator>
      <dc:date>2025-01-02T19:38:19Z</dc:date>
    </item>
  </channel>
</rss>

