<?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: XML errore when using python SDK on SPlunk balanced url in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488797#M8737</link>
    <description>&lt;P&gt;So it worked with new splunk python sdk ?&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2020 10:59:46 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2020-04-29T10:59:46Z</dc:date>
    <item>
      <title>XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488792#M8732</link>
      <description>&lt;P&gt;Hi to all, i get a strange errorr using python SDK when connecting to balanced url instead of single host.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;HOST = "splunk.balanced.url"
PORT = 8089
USERNAME = "admin"
PASSWORD = "changeme"
SCHEME = "https"
APP = "my_app"

# Create a Service instance and log in to Splunk

service = client.connect(
          host=HOST,
          port=PORT,
          username=USERNAME,
          password=PASSWORD,
          scheme=SCHEME,
          app=APP
          )

for app in service.apps:
    print app.name
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But i got this error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Traceback (most recent call last):
  File "test_connection.py", line 32, in &amp;lt;module&amp;gt;
    verify=False
  File "/opt/splunk/etc/apps/framework/contrib/splunk-sdk-python/splunklib/client.py", line 288, in connect
    return Service(**kwargs).login()
  File "/opt/splunk/etc/apps/framework/contrib/splunk-sdk-python/splunklib/binding.py", line 753, in login
    session = XML(body).findtext("./sessionKey")
  File "/usr/lib64/python2.6/xml/etree/ElementTree.py", line 964, in XML
    return parser.close()
  File "/usr/lib64/python2.6/xml/etree/ElementTree.py", line 1254, in close
    self._parser.Parse("", 1) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If i connect directly to the splunk host search head i got correct result: all app name.&lt;BR /&gt;Bhind the balanced url there is only one host at the moment (the same host from which i get correct result).&lt;BR /&gt;Someone got a similar problem? Could be a certificate issue? It seems that the XML returned is not correct.&lt;/P&gt;
&lt;P&gt;Thanks very much and regards&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 18:14:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488792#M8732</guid>
      <dc:creator>maurelio79</dc:creator>
      <dc:date>2020-06-07T18:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488793#M8733</link>
      <description>&lt;P&gt;When you say balanced URL, do you mean Load-balancer URL ? If yes then have you configured VIP on port 8089 in LB ?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 09:14:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488793#M8733</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-04-29T09:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488794#M8734</link>
      <description>&lt;P&gt;Yes LOAD balancer URL and a simple curl with -k it's working. &lt;BR /&gt;
It seems that the response is an empty body with SDK&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 09:42:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488794#M8734</guid>
      <dc:creator>maurelio79</dc:creator>
      <dc:date>2020-04-29T09:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488795#M8735</link>
      <description>&lt;P&gt;It looks like you are running splunk-sdk-python which ships with splunk itself and while looking at version of that SDK it is very old. I'll suggest you to download latest Splunk Python SDK from &lt;A href="https://github.com/splunk/splunk-sdk-python/releases"&gt;https://github.com/splunk/splunk-sdk-python/releases&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If it will not work with latest version of Splunk Python SDK then, can you please run below command and check whether you are receiving sessionKey or not.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -vk &lt;A href="https://your_lb_url:8089/services/auth/login" target="test_blank"&gt;https://your_lb_url:8089/services/auth/login&lt;/A&gt; --data-urlencode username=your_username --data-urlencode password='your_password'
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 10:13:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488795#M8735</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-04-29T10:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488796#M8736</link>
      <description>&lt;P&gt;I tried and i got a session key, so what it means? An old sdk version? But why the problem is present only if i pass via LB URL? It's very strange&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 10:58:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488796#M8736</guid>
      <dc:creator>maurelio79</dc:creator>
      <dc:date>2020-04-29T10:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488797#M8737</link>
      <description>&lt;P&gt;So it worked with new splunk python sdk ?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 10:59:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488797#M8737</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-04-29T10:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488798#M8738</link>
      <description>&lt;P&gt;Still not tried. It worked the curl retreiving the session key. I will try with new SDK and write here the result&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 12:19:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488798#M8738</guid>
      <dc:creator>maurelio79</dc:creator>
      <dc:date>2020-04-29T12:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488799#M8739</link>
      <description>&lt;P&gt;We have python 2.6.6, so i'm not sure i can test the new sdk, it requires python &amp;gt; 2.7&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 12:31:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488799#M8739</guid>
      <dc:creator>maurelio79</dc:creator>
      <dc:date>2020-04-29T12:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488800#M8740</link>
      <description>&lt;P&gt;Maybe it's due to python 2.6 , if you have any other host which is running python 2.7 then I'll suggest to try on that server.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 13:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488800#M8740</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-04-29T13:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: XML errore when using python SDK on SPlunk balanced url</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488801#M8741</link>
      <description>&lt;P&gt;For the moment we "solved" the issue modifyng the file binding.py.&lt;BR /&gt;
Inside function handler we modified the function reqeust from&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; def request(url, message, **kwargs):
        scheme, host, port, path = _spliturl(url)
        body = message.get("body", "")
        head = {
            "Content-Length": str(len(body)),
            "Host": host,
            "User-Agent": "splunk-sdk-python/0.1",
            "Accept": "*/*",
        } # defaults
        for key, value in message["headers"]:
            head[key] = value
        method = message.get("method", "GET")

        connection = connect(scheme, host, port)
        try:
            connection.request(method, path, body, head)
            if timeout is not None:
                connection.sock.settimeout(timeout)
            response = connection.getresponse()
        finally:
            connection.close()


        return {
            "status": response.status,
            "reason": response.reason,
            "headers": response.getheaders(),
            "body": ResponseReader(response),
        }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; def request(url, message, **kwargs):
        scheme, host, port, path = _spliturl(url)
        body = message.get("body", "")
        head = {
            "Content-Length": str(len(body)),
            "Host": host,
            "User-Agent": "splunk-sdk-python/0.1",
            "Accept": "*/*",
        } # defaults
        for key, value in message["headers"]:
            head[key] = value
        method = message.get("method", "GET")

        connection = connect(scheme, host, port)
        try:
            connection.request(method, path, body, head)
            if timeout is not None:
                connection.sock.settimeout(timeout)
            response = connection.getresponse()
        finally:
        #    connection.close()
            pass

        return {
            "status": response.status,
            "reason": response.reason,
            "headers": response.getheaders(),
            "body": ResponseReader(response),
        }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically we removed the connection.close()&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 13:48:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/XML-errore-when-using-python-SDK-on-SPlunk-balanced-url/m-p/488801#M8741</guid>
      <dc:creator>maurelio79</dc:creator>
      <dc:date>2020-04-29T13:48:14Z</dc:date>
    </item>
  </channel>
</rss>

