Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponseReader object has no attribute 'sid' #581

Open
GitAmi55 opened this issue Aug 27, 2024 · 1 comment
Open

ResponseReader object has no attribute 'sid' #581

GitAmi55 opened this issue Aug 27, 2024 · 1 comment

Comments

@GitAmi55
Copy link

GitAmi55 commented Aug 27, 2024

Describe the bug
I recieve the error while performing search on splunk using Splunklib.

To Reproduce
Steps to reproduce the behavior:

  1. Install Splunklib library
  2. Peform search on SPlunk using Splunk API
  3. Code is given below

Expected behavior
Search should be performed and desired results should be shown.

Splunk (please complete the following information):

  • Version: Splunk Enterprise. Version: 9.1.5 (on server)
  • OS: [e.g. MacOS 14.3]

SDK (please complete the following information):

  • Version: Java JDK version 8
  • Language Runtime Version: [e.g. Python 3.12]
  • OS: [e.g. MacOS 14.3 ]

code:

I am currently trying to connect with splunk server, make a search and get the results back using SplunkLib. I was able to make connection, and make small interactions like get all apps. However, when I perform search, I get an error and results stored are empty. Here is the code:

def connect_to_splunk(host=“Linktosplunk, port=8089):
    splunk_username = os.environ.get('Splunk_Username')
    plunk_password = os.environ.get('Splunk_Password')

    if not splunk_username or not splunk_password:
        raise ValueError("Splunk_Username and Splunk_Password environment variables must be set")

    try:
        service = connect(host=host, port=port, username=splunk_username, password=splunk_password,app=“MyApp", timeout=30)
        return service

    except Exception as e:
        raise ConnectionError(f"Failed to connect to Splunk: {e}")


def splunk_query_search():
    connection= connect_to_splunk()
    search_query = "search tag::host=‘int’ method=PUT 1234 sourcetype=XZY earliest=-15m@m latest=@m"

    try:
        search_job = connection.jobs.oneshot(search_query)
        sid = search_job.sid  # Get the SID from the search job

        results = search_job.read() # Retrieve search results
        return [result for result in results]  # Convert results to a list

    except Exception as e:
        print(f"Error during search: {e}")
        return []  # Return empty list on error

however, I get this error on report:

INFO | Error during search: 'ResponseReader' object has no attribute 'sid'
${result} = []

How can I fix this? I am not using ResponseReader object anywhere in the code too..

Any lead would be helpful. Thank you..!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@GitAmi55 and others