From f66d2e639c6efce966da4572c67d3d7d56f8e9e0 Mon Sep 17 00:00:00 2001 From: Rodrigo <95635797+poly-rodr@users.noreply.github.com> Date: Fri, 19 Jul 2024 20:05:25 -0300 Subject: [PATCH] Handling the non-json API responses --- py_clob_client/http_helpers/helpers.py | 7 ++++++- py_clob_client/signing/eip712.py | 7 ++++--- setup.py | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/py_clob_client/http_helpers/helpers.py b/py_clob_client/http_helpers/helpers.py index 940d2d6..7f4cbee 100644 --- a/py_clob_client/http_helpers/helpers.py +++ b/py_clob_client/http_helpers/helpers.py @@ -40,7 +40,12 @@ def request(endpoint: str, method: str, headers=None, data=None): ) if resp.status_code != 200: raise PolyApiException(resp) - return resp.json() + + try: + return resp.json() + except requests.JSONDecodeError: + return resp.text + except requests.RequestException: raise PolyApiException(error_msg="Request exception!") diff --git a/py_clob_client/signing/eip712.py b/py_clob_client/signing/eip712.py index 26ea5b3..2d08eff 100644 --- a/py_clob_client/signing/eip712.py +++ b/py_clob_client/signing/eip712.py @@ -21,7 +21,8 @@ def sign_clob_auth_message(signer: Signer, timestamp: int, nonce: int) -> str: message=MSG_TO_SIGN, ) chain_id = signer.get_chain_id() - auth_struct_hash = "0x" + keccak( - clob_auth_msg.signable_bytes(get_clob_auth_domain(chain_id)) - ).hex() + auth_struct_hash = ( + "0x" + + keccak(clob_auth_msg.signable_bytes(get_clob_auth_domain(chain_id))).hex() + ) return "0x" + signer.sign(auth_struct_hash) diff --git a/setup.py b/setup.py index 68f3a9e..576ca62 100644 --- a/setup.py +++ b/setup.py @@ -20,8 +20,8 @@ "poly_eip712_structs>=0.0.1", "py-order-utils>=0.3.1", "python-dotenv", - "requests" - ], + "requests", + ], project_urls={ "Bug Tracker": "https://github.com/Polymarket/py-clob-client/issues", },