Skip to content

Commit 5160396

Browse files
committed
v0.1.56 handling empty responses also in single batch requests
1 parent 66acbae commit 5160396

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

IceCreamSwapWeb3/BatchRetryMiddleware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from time import sleep
22

3+
from web3.exceptions import BadResponseFormat
34
from web3.manager import NULL_RESPONSES
45
from web3.middleware import Web3Middleware
56

@@ -28,6 +29,10 @@ def request_wrapper(method, params):
2829
response = make_batch_request.__self__.make_request(method, params)
2930
if "error" in response and self._w3.should_retry:
3031
raise Exception(response["error"].get("message") or "Unknown RPC Error")
32+
if response.get("jsonrpc") != "2.0":
33+
raise BadResponseFormat("The response was in an unexpected format and unable to be parsed. "
34+
"The \"jsonrpc\" field must be present with a value of \"2.0\". "
35+
f"The raw response is: {response}")
3136
if ("eth_getBlockBy" in method and response.get("result") in NULL_RESPONSES) and self._w3.should_retry:
3237
raise Exception("Block not found")
3338
return response

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.1.55'
3+
VERSION = '0.1.56'
44
DESCRIPTION = 'IceCreamSwap Web3.py wrapper'
55
LONG_DESCRIPTION = 'IceCreamSwap Web3.py wrapper with automatic retries, multicall and other advanced functionality'
66

0 commit comments

Comments
 (0)