<?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 Using splunk-sdk-python 1.6.5, why am I getting the following error?: &amp;quot;splunklib.binding.HTTPError cannot be found&amp;quot; in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Using-splunk-sdk-python-1-6-5-why-am-I-getting-the-following/m-p/417206#M7274</link>
    <description>&lt;P&gt;I installed splunk-sdk-python version 1.6.5 using pip on Mac OS 10.11.6 and have had moderate success cannibalizing example code from the kvstore.py. But now, I've run into an issue.&lt;/P&gt;

&lt;P&gt;I expect to throw an error when I use "query_by_id" with a nonexistent key.  Unfortunately, my stack trace states that the error object called "splunklib.binding.HTTPError" cannot be found.  I can see the object being defined in the "binding.py" file.&lt;/P&gt;

&lt;P&gt;I have lengthy experience coding in Java, but I am switching to Python, so I could be making a rookie mistake without knowing it.  Does anyone see the problem?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;This is the error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Traceback (most recent call last):
  File "./dc2kv.py", line 108, in main
    kvRecord = json.dumps(collection.data.query_by_id(recID))
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/client.py", line 3642, in query_by_id
    return json.loads(self._get(UrlEncoded(str(id))).body.read().decode('utf-8'))
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/client.py", line 3612, in _get
    return self.service.get(self.path + url, owner=self.owner, app=self.app, sharing=self.sharing, **kwargs)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 289, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 71, in new_f
    val = f(*args, **kwargs)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 669, in get
    response = self.http.get(path, self._auth_headers, **query)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 1167, in get
    return self.request(url, { 'method': "GET", 'headers': headers })
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 1228, in request
    raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 404 Not Found -- Could not find object.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./dc2kv.py", line 134, in &amp;lt;module&amp;gt;
    main()
  File "./dc2kv.py", line 109, in main
    except HTTPError as herror:
NameError: name 'HTTPError' is not defined
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/python -tt
# dc2kv.py

import sys
import requests
import json
import splunklib.client as client
 #...
def main():
    # ...


    try:
        kvStoreConn = client.connect(**kwargs)
        print("Connected to KVStore Successfully")
        for collection in kvStoreConn.kvstore:
            print("  %s" % collection.name)

        collection = kvStoreConn.kvstore[props.get('dcCollection')]
        #print(json.dumps(collection.data.query()))
        #kvStoreConn.logout()
    except AuthenticationError:
        print("Failed to connect")
        sys.exit(1)

    for record in allRecords:
        recID = record.get('_id')
        print(recID)
        kvRecord = 'None'
        try:
            kvRecord = json.dumps(collection.data.query_by_id(recID))
        except HTTPError as herror:
            print ('Found HTTPError: ', herror)
        print('No record found.')
        if kvRecord == 'None':
            collection.insert(dumps(recID))
            print('Inserted %s', recID)
        else:
            collection.update(id = recID, data = record)
            print('Updated %s', recID)

        kvStoreConn.logout()

        sys.exit(1)
            kvStoreConn.logout()

    sys.exit(1)

if __name__ == '__main__':
  main()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 21:33:34 GMT</pubDate>
    <dc:creator>organus</dc:creator>
    <dc:date>2020-09-29T21:33:34Z</dc:date>
    <item>
      <title>Using splunk-sdk-python 1.6.5, why am I getting the following error?: "splunklib.binding.HTTPError cannot be found"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-splunk-sdk-python-1-6-5-why-am-I-getting-the-following/m-p/417206#M7274</link>
      <description>&lt;P&gt;I installed splunk-sdk-python version 1.6.5 using pip on Mac OS 10.11.6 and have had moderate success cannibalizing example code from the kvstore.py. But now, I've run into an issue.&lt;/P&gt;

&lt;P&gt;I expect to throw an error when I use "query_by_id" with a nonexistent key.  Unfortunately, my stack trace states that the error object called "splunklib.binding.HTTPError" cannot be found.  I can see the object being defined in the "binding.py" file.&lt;/P&gt;

&lt;P&gt;I have lengthy experience coding in Java, but I am switching to Python, so I could be making a rookie mistake without knowing it.  Does anyone see the problem?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;This is the error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Traceback (most recent call last):
  File "./dc2kv.py", line 108, in main
    kvRecord = json.dumps(collection.data.query_by_id(recID))
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/client.py", line 3642, in query_by_id
    return json.loads(self._get(UrlEncoded(str(id))).body.read().decode('utf-8'))
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/client.py", line 3612, in _get
    return self.service.get(self.path + url, owner=self.owner, app=self.app, sharing=self.sharing, **kwargs)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 289, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 71, in new_f
    val = f(*args, **kwargs)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 669, in get
    response = self.http.get(path, self._auth_headers, **query)
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 1167, in get
    return self.request(url, { 'method': "GET", 'headers': headers })
  File "/Users/dcrocker/anaconda3/lib/python3.6/site-packages/splunklib/binding.py", line 1228, in request
    raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 404 Not Found -- Could not find object.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./dc2kv.py", line 134, in &amp;lt;module&amp;gt;
    main()
  File "./dc2kv.py", line 109, in main
    except HTTPError as herror:
NameError: name 'HTTPError' is not defined
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/python -tt
# dc2kv.py

import sys
import requests
import json
import splunklib.client as client
 #...
def main():
    # ...


    try:
        kvStoreConn = client.connect(**kwargs)
        print("Connected to KVStore Successfully")
        for collection in kvStoreConn.kvstore:
            print("  %s" % collection.name)

        collection = kvStoreConn.kvstore[props.get('dcCollection')]
        #print(json.dumps(collection.data.query()))
        #kvStoreConn.logout()
    except AuthenticationError:
        print("Failed to connect")
        sys.exit(1)

    for record in allRecords:
        recID = record.get('_id')
        print(recID)
        kvRecord = 'None'
        try:
            kvRecord = json.dumps(collection.data.query_by_id(recID))
        except HTTPError as herror:
            print ('Found HTTPError: ', herror)
        print('No record found.')
        if kvRecord == 'None':
            collection.insert(dumps(recID))
            print('Inserted %s', recID)
        else:
            collection.update(id = recID, data = record)
            print('Updated %s', recID)

        kvStoreConn.logout()

        sys.exit(1)
            kvStoreConn.logout()

    sys.exit(1)

if __name__ == '__main__':
  main()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:33:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-splunk-sdk-python-1-6-5-why-am-I-getting-the-following/m-p/417206#M7274</guid>
      <dc:creator>organus</dc:creator>
      <dc:date>2020-09-29T21:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using splunk-sdk-python 1.6.5, why am I getting the following error?: "splunklib.binding.HTTPError cannot be found"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-splunk-sdk-python-1-6-5-why-am-I-getting-the-following/m-p/417207#M7275</link>
      <description>&lt;P&gt;Okay, I got it.  I had to import the entire library, and I had to fully qualify the exception name.&lt;/P&gt;

&lt;P&gt;BTW, there are also other problems in the code, so don't use it as a template.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#...
import splunklib
#...
        except splunklib.binding.HTTPError as herror:
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 15:17:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-splunk-sdk-python-1-6-5-why-am-I-getting-the-following/m-p/417207#M7275</guid>
      <dc:creator>organus</dc:creator>
      <dc:date>2018-10-05T15:17:25Z</dc:date>
    </item>
  </channel>
</rss>

