Getting Data In

With Python Splunk SDK stop raise HTTPError(response) for 504 responses

cdhippen
Path Finder

Our Splunk environment sometimes throws 504 errors when we query via the API, which has been a known issue for a while. We recently moved a connector to using the Python sdk over a hacky script we had. In our API based one, we were able to catch the 504 errors that pop up randomly and loop back and try again when they happen. With the Python SDK, the best I've been able to find out to do is this:

flag = True
        while flag:
            try:d
                job = self.service.jobs.(create|results|any jobs./job. call)(query, **kwargs_normalsearch)
                flag = False
            except binding.HTTPError:
                    print('Splunk 504 Error'
                pass
            pass

But this has a lot of problems, especially since if any other errors besides a 504 pop up that would actually indicate a real problem, I'm going to be stuck in a never ending loop. If there's a parameter or something for the jobs/job object that allows for ignoring specific HTTP errors? I'd really like to stop wrapping these calls in silly while True loops. If not is there a way to extract the status from the exception that's raised and at least be able to handle different status codes in different ways?

0 Karma
Get Updates on the Splunk Community!

Index This | Divide 100 by half. What do you get?

November 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

❄️ Celebrate the season with our December lineup of Community Office Hours, Tech Talks, and Webinars! ...

Splunk and Fraud

Watch Now!Watch an insightful webinar where we delve into the innovative approaches to solving fraud using the ...