diff --git a/scorum/api/request.py b/scorum/api/request.py index 9ecca96..c4a4f7f 100644 --- a/scorum/api/request.py +++ b/scorum/api/request.py @@ -16,20 +16,21 @@ def get_curl_cli(url, api, method, args): def call(url, api, method, args, retries=5): payload = to_payload(method, api, args) - + r = 0 while retries: try: r = requests.post(url, json=payload) retries = 0 except Exception as e: - log.error("Error during request: %s", e) - log.warning("Remain attempts: %d", retries) + log.error("Error during request: %s\n Remain attempts: %d", e, retries) time.sleep(0.5) retries -= 1 + if not isinstance(r, requests.Response): + raise ConnectionError("Failed to retrieve response from: %s", url) + try: response = json.loads(r.text) return response["result"] - except: + except KeyError: log.error("request failed with code: %d: %s\n%s" % (r.status_code, r.reason, r.text)) - return None