Skip to content

Commit

Permalink
start replacing requests with httpx
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Oct 23, 2023
1 parent 8a7c6a1 commit 766158c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions skycalc_ipy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Dict
from types import ModuleType

import requests
import httpx

from astropy.io import fits

Expand Down Expand Up @@ -423,17 +423,21 @@ def call(self, test=False):
return

try:
response = requests.post(
self.url, data=json.dumps(self.params), timeout=self.REQUEST_TIMEOUT
)
except requests.exceptions.RequestException as err:
self._handle_exception(
err, "Exception raised trying to POST request " + self.url
response = httpx.post(
self.url, json=self.params, timeout=self.REQUEST_TIMEOUT
)
return
response.raise_for_status()
except httpx.RequestError as err:
logging.exception("An error occurred while requesting %s.",
err.request.url)
raise err
except httpx.HTTPStatusError as err:
logging.error("Error response %s while requesting %s.",
err.response.status_code, err.request.url)
raise err

try:
res = json.loads(response.text)
res = response.json()
status = res["status"]
tmpdir = res["tmpdir"]
except (KeyError, ValueError) as err:
Expand Down

0 comments on commit 766158c

Please sign in to comment.