Python Requests JSON-RPC fails with some calls

Hello,

I am playing around with Infura and decided to test how it would work with python requests library. I noticed that some of calls do not work properly.

I can get blockByNumber just fine, like this:

url = “https://mainnet.infura.io/v3/API-KEY
request_content = {“jsonrpc”:“2.0”, “method”: “eth_blockNumber”, “params”: , “id”: 1}
request = requests.post(url, json=request_content)

Returns expected blockNumber in results

However, some POST fail when used with requests for unknown reasons. This doesn’t happen when executing with curl. Ie.

url = “https://mainnet.infura.io/v3/API-KEY
request_content = {“jsonrpc”:“2.0”, “method”: “eth_getBlockByNumber”, “params”: [“0xA7EB23”, “false”], “id”: 1}
request = requests.post(url, json=request_content)

eth_getBlockByNumber works fine with curl, but fails with requests.

{“code”:-32602,“message”:“invalid arguments to eth_getBlockByNumber”}

I suspect that “false” is a culprit here, as queries without boolean values seem to pass fine. Ie. eth-getCode

use from web3.providers.base import JSONBaseProvider

1 Like

Welcome to the Infura community, @B.Shaftoe! @kaleb-keny’s suggestion is a great first step. If that doesn’t work, please update this thread and we’ll help you figure out what’s going on!

Thank you both for help.

@kaleb-keny suggestion does solve my problem, using web3.py seems to be a better way to connect with an ethereum node anyhow.