Skip to content

How to specify timeout value? #615

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

Open
retzero opened this issue May 7, 2025 · 0 comments
Open

How to specify timeout value? #615

retzero opened this issue May 7, 2025 · 0 comments

Comments

@retzero
Copy link

retzero commented May 7, 2025

Hello.
Below is example code. It works fine but timed out after 2 minutes in the firewall blocked host machine.
So I'd want to set shorter timeout value, eg, 30 seconds.
How can I set this value in your SDK?

service = client.connect(
    scheme='http',
    host=os.getenv('SPLUNK_HOST'),
    port=int(os.getenv('SPLUNK_PORT')),
    splunkToken=os.getenv('SPLUNK_TOKEN'))

result = []
kwargs_oneshot = {"earliest_time": "-2d@d",
                  "latest_time": "-0d@d",
                  "output_mode": 'json',
                  "count": 0}
searchquery_oneshot = '''search index="my_test_index" earliest=-2d@d
           | table column_1 column_2 column_3'''

oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot, **kwargs_oneshot)

Log snippet;

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 10, in splunk_search
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 510, in jobs
    return Jobs(self)
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 3051, in __init__
    if not service.disable_v2_api:
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 714, in disable_v2_api
    if self.splunk_instance.lower() == 'cloud':
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 705, in splunk_instance
    splunk_info = self.info
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 479, in info
    response = self.get("/services/server/info")
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 318, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 76, in new_f
    val = f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 737, in get
    response = self.http.get(path, all_headers, **query)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 1272, in get
    return self.request(url, {'method': "GET", 'headers': headers})
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 1334, in request
    response = self.handler(url, message, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 1488, in request
    connection.request(method, path, body, head)
  File "/usr/local/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/usr/local/lib/python3.10/http/client.py", line 942, in connect
    self.sock = self._create_connection(
  File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
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