JSON-RPC payload works from python, fails from curl

This works:

import json
import requests
from requests.auth import HTTPBasicAuth

url = "http://localhost:14000/api/"
headers = {'content-type': 'application/json'}
auth = HTTPBasicAuth('rpc', 123456)

payload = {
  "method": "get_sends",
  "params": {"order_by": 'tx_hash',
             "order_dir": 'asc',
             "start_block": 280537,
             "end_block": 320539},
  "jsonrpc": "2.0",
  "id": 0,
}

response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth)
print("Response: ", response.text)

This doesn’t:

curl -X POST http://127.0.0.1:14000/api/ --user rpc:123456 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{ "method": "get_sends", "params": {"order_by": 'tx_hash', "order_dir": 'asc', "start_block": 280537, "end_block": 320539}, "jsonrpc": "2.0", "id": 0}'

{"message": "Invalid Request", "data": "Invalid JSON-RPC 2.0 request format", "code": -32600}

Can anyone see what is wrong with the curl example?

FWIW , I reproduced this error on my curl. However, I’ve noticed that the following curl works fine for me:

curl -v -X POST http://127.0.0.1:14000/api/ --user rpc:1234 -H ‘Content-Type: application/json; charset=UTF-8’ -H ‘Accept: application/json, text/javascript’ --data-binary ‘{ “method”: “get_sends”, “params”: {“start_block”: 280537, “end_block”: 320539}, “jsonrpc”: “2.0”, “id”: 0}’

(Notice that the order_ params were removed) Is there a limit to the length of the command maybe? is the data-binary getting truncated perhaps?

Thanks a bunch!

Yesterday I spent hours trying to use those payload examples with curl until I thought to try them in Python first (where they worked). Unbelievable.

Maybe I’ll use a network tracing utility to investigate this further.

After one more hour of troubleshooting and preparing a bug report to curl, I realized that this below works. It wasn’t the length but the damn single quotes around non-numeric order values. Python3 takes the both, curl doesn’t.

$ curl -vv -X POST http://127.0.0.1:14000/api/ --user rpc:123456 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary  '{ "method": "get_sends", "params": {"order_by": "tx_hash","order_dir": "asc", "start_block": 280537, "end_block": 320539}, "jsonrpc": "2.0", "id": 0}

Then I went to check the standard and there it sez double quotes should be used. TFM’s need to highlight this, it’s been a persistent source of frustration.

Edit: a pull request related to curl examples has been created. Ultimately all examples should be use the double quotes, but for now at least there’s something for those who read the docs.