Skip to content

Commit

Permalink
use a session instead of requests directly
Browse files Browse the repository at this point in the history
 * enable persistent sessions to be used instead of an always-new
   session for each request
  • Loading branch information
JunAishima committed Oct 9, 2024
1 parent 9e24b95 commit 80d718a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions conftrak/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import ujson
from ..exceptions import ConfTrakNotFoundException


session = requests.Session()


def doc_or_uid_to_uid(doc_or_uid):
"""Given Document or uid return the uid
Expand Down Expand Up @@ -38,7 +42,7 @@ def _get(url, params):
Results of the query
"""
r = requests.get(url, ujson.dumps(params))
r = session.get(url, ujson.dumps(params))
if r.status_code == 500 and "found" in r.reason:
raise ConfTrakNotFoundException(r.reason)
r.raise_for_status()
Expand All @@ -56,7 +60,7 @@ def _post(url, data):
Entries to be inserted to database
"""
r = requests.post(url,
r = session.post(url,
data=ujson.dumps(data))
r.raise_for_status()
return r.json()
Expand Down Expand Up @@ -86,7 +90,7 @@ def _put(url, query, update):
"""
update_cont = {'query': query, 'update': update}
r = requests.put(url,
r = session.put(url,
data=ujson.dumps(update_cont))
r.raise_for_status()

Expand All @@ -113,7 +117,7 @@ def _delete(url, params):
"""
url_with_params = "{}?{}".format(url, ujson.dumps(params))
r = requests.delete(url_with_params)
r = session.delete(url_with_params)
r.raise_for_status()


0 comments on commit 80d718a

Please sign in to comment.