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

'Message' object is not subscriptable #538

Closed
FreezeLuiz opened this issue Aug 10, 2023 · 1 comment
Closed

'Message' object is not subscriptable #538

FreezeLuiz opened this issue Aug 10, 2023 · 1 comment

Comments

@FreezeLuiz
Copy link

Describe the bug
While extracting results from a saved Splunk search that leverages an appended 'inputlookup.' I get an error saying 'Message' object is not subscriptable. The issue resides in the 'Message' object being displayed first as an informational message (e.g: INFO: [subsearch]: Successfully read lookup file) from Splunklib.results, which makes the return value from splunklib.results.JSONResultsReader not subscriptable.

To Reproduce
Steps to reproduce the behavior:

  1. Save a search in splunk as a report and make sure to use the append command or any subsearch command.
  2. Use the splunklib.results.JSONResultsReader to parse the search results in python.
  3. Try iterating on the report results, you will get an exception because of the 'Message' object returned from the parser.

Expected behavior
Informational messages should only be displayed when a debugging flag is active, debugging flags should be disabled by default.

Logs or Screenshots

'Message' object is not subscriptable

Informational message from parser:
INFO: [subsearch]: Successfully read lookup file '/path/of/lookup/file'.

Types of values returned from parser:
<class 'splunklib.results.Message'>
<class 'dict'>
<class 'dict'>

SDK:

  • Version: 1.7.4
  • Language Runtime Version: Python 3.7.10
  • OS: Ubuntu 23.04

Additional Context

  • If there is already something built-in the SDK to prevent these 'Message' objects, kindly let me know. Nothing in the documentation is explicitly mentioning how to disable info 'Message' objects.
@FreezeLuiz
Copy link
Author

Filtering on the instance type fixed the issue.

import results
        response = ... # the body of an HTTP response
        reader = results.JSONResultsReader(response)
        for result in reader:
            if isinstance(result, dict):
                print "Result: %s" % result
            elif isinstance(result, results.Message):
                print "Message: %s" % result
        print "is_preview = %s " % reader.is_preview

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

1 participant