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

Add requests timeout #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ swis.query("SELECT NodeID from Orion.Nodes")
```

## Setting Timeout
#be default, timeout is set to 10 seconds

```python
import orionsdk
import requests

session = requests.Session()
session.timeout = 30 # Set your timeout in seconds
swis = orionsdk.SwisClient("SolarWinds-Orion", "username", "password", verify="server.pem", session=session)
swis = orionsdk.SwisClient("SolarWinds-Orion", "username", "password", timeout=5, verify="server.pem", session=session)
swis.query("SELECT NodeID from Orion.Nodes")
```

Expand Down
4 changes: 3 additions & 1 deletion orionsdk/swisclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def _json_serial(obj):


class SwisClient:
def __init__(self, hostname, username, password, port=17774, verify=False, session=None):
def __init__(self, hostname, username, password, port=17774, timeout=10, verify=False, session=None):
self.url = "https://{}:{}/SolarWinds/InformationService/v3/Json/".\
format(hostname, port)
self._session = session or requests.Session()
self._session.auth = (username, password)
self._session.headers.update({'Content-Type': 'application/json'})
self._session.verify = verify
self._timeout = timeout

def query(self, query, **params):
return self._req(
Expand Down Expand Up @@ -54,6 +55,7 @@ def bulkdelete(self, uris):
def _req(self, method, frag, data=None):
resp = self._session.request(method,
self.url + frag,
timeout = self._timeout
data=json.dumps(data, default=_json_serial))

# try to extract reason from response when request returns error
Expand Down