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 907441e commit 3b89609
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions analysisstore/client/asutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import six


session = requests.Session()


def get_document(url, doc_type, as_json, contents):
r = requests.get(url, params=ujson.dumps(contents))
r = session.get(url, params=ujson.dumps(contents))
r.raise_for_status()
content = ujson.loads(r.text)
if as_json:
Expand All @@ -18,7 +21,7 @@ def get_document(url, doc_type, as_json, contents):

def post_document(url, contents):
try:
r = requests.post(url, data=ujson.dumps(contents))
r = session.post(url, data=ujson.dumps(contents))
except ConnectionError:
raise ConnectionError('No AnalysisStore server found')
r.raise_for_status() # this is for catching server side issue.
Expand Down

0 comments on commit 3b89609

Please sign in to comment.