<?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 REST api code failing. in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/REST-api-code-failing/m-p/696468#M11645</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I ran the following code -&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;from __future__ import print_function
import urllib.request, urllib.parse, urllib.error
import httplib2
from xml.dom import minidom

baseurl = '&amp;lt;url&amp;gt;'
userName = '&amp;lt;username&amp;gt;'
password = '&amp;lt;password&amp;gt;'

searchQuery = &amp;lt;query&amp;gt;

# Authenticate with server.
# Disable SSL cert validation. Splunk certs are self-signed.
serverContent = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/auth/login',
    'POST', headers={}, body=urllib.parse.urlencode({'username':userName, 'password':password}))[1]

sessionKey = minidom.parseString(serverContent).getElementsByTagName('sessionKey')[0].childNodes[0].nodeValue

# Remove leading and trailing whitespace from the search
searchQuery = searchQuery.strip()

# If the query doesn't already start with the 'search' operator or another
# generating command (e.g. "| inputcsv"), then prepend "search " to it.
if not (searchQuery.startswith('search') or searchQuery.startswith("|")):
    searchQuery = 'search ' + searchQuery
   
print(searchQuery)

# Run the search.
# Again, disable SSL cert validation.
print(httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/search/jobs','POST',
    headers={'Authorization': 'Splunk %s' % sessionKey},body=urllib.parse.urlencode({'search': searchQuery}))[1])&lt;/LI-CODE&gt;
&lt;P&gt;I get this error - "TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"&lt;/P&gt;
&lt;P&gt;Is my url format wrong?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 16 Aug 2024 14:13:28 GMT</pubDate>
    <dc:creator>MK3</dc:creator>
    <dc:date>2024-08-16T14:13:28Z</dc:date>
    <item>
      <title>REST api code failing.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/REST-api-code-failing/m-p/696468#M11645</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I ran the following code -&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;from __future__ import print_function
import urllib.request, urllib.parse, urllib.error
import httplib2
from xml.dom import minidom

baseurl = '&amp;lt;url&amp;gt;'
userName = '&amp;lt;username&amp;gt;'
password = '&amp;lt;password&amp;gt;'

searchQuery = &amp;lt;query&amp;gt;

# Authenticate with server.
# Disable SSL cert validation. Splunk certs are self-signed.
serverContent = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/auth/login',
    'POST', headers={}, body=urllib.parse.urlencode({'username':userName, 'password':password}))[1]

sessionKey = minidom.parseString(serverContent).getElementsByTagName('sessionKey')[0].childNodes[0].nodeValue

# Remove leading and trailing whitespace from the search
searchQuery = searchQuery.strip()

# If the query doesn't already start with the 'search' operator or another
# generating command (e.g. "| inputcsv"), then prepend "search " to it.
if not (searchQuery.startswith('search') or searchQuery.startswith("|")):
    searchQuery = 'search ' + searchQuery
   
print(searchQuery)

# Run the search.
# Again, disable SSL cert validation.
print(httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/search/jobs','POST',
    headers={'Authorization': 'Splunk %s' % sessionKey},body=urllib.parse.urlencode({'search': searchQuery}))[1])&lt;/LI-CODE&gt;
&lt;P&gt;I get this error - "TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"&lt;/P&gt;
&lt;P&gt;Is my url format wrong?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:13:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/REST-api-code-failing/m-p/696468#M11645</guid>
      <dc:creator>MK3</dc:creator>
      <dc:date>2024-08-16T14:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: REST api code failing.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/REST-api-code-failing/m-p/696477#M11646</link>
      <description>&lt;P&gt;Hard to say without knowing your base url. The error 10060 means your code can't connect to the destination server. Either you specified a wrong machine to connect to or you're having some network issues. Can you connect manually to the API endpoint from the host you're running your code on?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 13:05:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/REST-api-code-failing/m-p/696477#M11646</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-08-16T13:05:10Z</dc:date>
    </item>
  </channel>
</rss>

