<?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 Unable to reference .splunkrc file from Splunk Python SDK in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/278893#M3489</link>
    <description>&lt;P&gt;I created the .splunkrc file and correctly stored it in C:\Users\username.splunkrc&lt;BR /&gt;
I filled it out with correct credentials.&lt;/P&gt;

&lt;P&gt;1) I am trying to access KV store (&lt;STRONG&gt;the credentials work when I enter via cmd line but not when using .splunkrc&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;opts = parse(sys.argv[1:], {}, ".splunkrc")
opts.kwargs["owner"] = "nobody"
opts.kwargs["app"] = "search"
service = client.connect(**opts.kwargs)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get this error: &lt;CODE&gt;socket.error: [Errno 10061] No connection could be made because the target machine actively refused it&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;2) How do I use the .splunkrc for a regular search query connect? I am currently doing this (hardcoded data):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# Create a Service instance and log in 
service = client.connect(
    host=HOST,
    port=PORT,
    username=USERNAME,
    password=PASSWORD)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Dec 2016 22:47:03 GMT</pubDate>
    <dc:creator>nsshey</dc:creator>
    <dc:date>2016-12-13T22:47:03Z</dc:date>
    <item>
      <title>Unable to reference .splunkrc file from Splunk Python SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/278893#M3489</link>
      <description>&lt;P&gt;I created the .splunkrc file and correctly stored it in C:\Users\username.splunkrc&lt;BR /&gt;
I filled it out with correct credentials.&lt;/P&gt;

&lt;P&gt;1) I am trying to access KV store (&lt;STRONG&gt;the credentials work when I enter via cmd line but not when using .splunkrc&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;opts = parse(sys.argv[1:], {}, ".splunkrc")
opts.kwargs["owner"] = "nobody"
opts.kwargs["app"] = "search"
service = client.connect(**opts.kwargs)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get this error: &lt;CODE&gt;socket.error: [Errno 10061] No connection could be made because the target machine actively refused it&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;2) How do I use the .splunkrc for a regular search query connect? I am currently doing this (hardcoded data):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# Create a Service instance and log in 
service = client.connect(
    host=HOST,
    port=PORT,
    username=USERNAME,
    password=PASSWORD)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2016 22:47:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/278893#M3489</guid>
      <dc:creator>nsshey</dc:creator>
      <dc:date>2016-12-13T22:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to reference .splunkrc file from Splunk Python SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/278894#M3490</link>
      <description>&lt;P&gt;Create a file called ".splunkrc" with the following in your $HOME directory:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=localhost
port=8089
username=restclient
password=splunkC0der
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, run the following as your splunk user:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk add user restclient -password "splunkC0der" -full-name 'REST client' -role admin
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Finally, you should be able to create the following login.py file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.client as client
import sys

if len(sys.argv) != 5:
        print "Syntax: login.py username password hostname port"
        sys.exit()

uid  = sys.argv[1];
pwd  = sys.argv[2];
host = sys.argv[3];
port = sys.argv[4];

try:
        service = client.connect(host=host, port=port, username=uid, password=pwd)

        print
        print 'Authenticated, token = [%s]' % service.token
        print

        service.logout()

except Exception, err:
        sys.stderr.write('\nError: %s\n\n' % str(err))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and run it successfully:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;python login.py
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Sep 2017 16:44:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/278894#M3490</guid>
      <dc:creator>jwalthour</dc:creator>
      <dc:date>2017-09-20T16:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to reference .splunkrc file from Splunk Python SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/519864#M3491</link>
      <description>&lt;P&gt;Hi jwalthour,&lt;/P&gt;&lt;P&gt;I'm new here and found your response here in community (even when far in the past) as I have same issue that .splunkrc file is not recognized.&lt;BR /&gt;My understanding was, that if I have this file correctly setup and stored, I do not need to enter any login data&lt;BR /&gt;to any Python script at all.&lt;/P&gt;&lt;P&gt;But if I understood your Python example correctly, it ask actively to enter credentials and host/port&amp;nbsp;&lt;BR /&gt;when I execute login.py&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 09:15:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-reference-splunkrc-file-from-Splunk-Python-SDK/m-p/519864#M3491</guid>
      <dc:creator>Ralf</dc:creator>
      <dc:date>2020-09-16T09:15:20Z</dc:date>
    </item>
  </channel>
</rss>

