Re: (context post by lachesis)

Participants: lachesis

I noticed from a hint that Satoshi dropped in the JSON-RPC password thread about so-called “Multiple Invocation” support in Bitcoin’s JSON-RPC.

As I run a site that polls bitcoind for payments to a large number of addresses twice a minute, I was intrigued. First of all, this isn’t JSON-RPC 2.0’s “Batch” support, where requests are submitted in an array and responses are received the same way: Code:request = [ {“jsonrpc”: “2.0”, “method”: “sum”, “params”: [1,2,4], “id”: “1”}, {“jsonrpc”: “2.0”, “method”: “subtract”, “params”: [42,23], “id”: “2”}, {“jsonrpc”: “2.0”, “method”: “get_data”, “id”: “9”} ] response = [ {“jsonrpc”: “2.0”, “result”: 7, “id”: “1”}, {“jsonrpc”: “2.0”, “result”: 19, “id”: “2”}, {“jsonrpc”: “2.0”, “result”: [“hello”, 5], “id”: “9”} ]

Instead, it’s something different, and I can’t figure out how to parse the responses in Python. Here’s a screen capture of a telnet session to the Bitcoin RPC server: Code:$ telnet localhost 8332 Trying 127.0.0.1… Connected to localhost. Escape character is ’^]’. POST / HTTP/1.1 Content-Type: text/plain Content-Length: 97

{“params”:],“id”:1,“method”:“getconnectioncount”} {“params”:],“id”:2,“method”:“getdifficulty”} HTTP/1.1 200 OK Connection: close Content-Length: 33 Content-Type: application/json Date: Sat, 08 Jul 2006 12:04:08 GMT Server: json-rpc/1.0

{“result”:8,“error”:null,“id”:1} HTTP/1.1 200 OK Connection: close Content-Length: 49 Content-Type: application/json Date: Sat, 08 Jul 2006 12:04:08 GMT Server: json-rpc/1.0

{“result”:181.5432893640505,“error”:null,“id”:2} Connection closed by foreign host. As you can see, the server replies with two complete HTTP 200 responses instead of (as I would have expected) one response with the two lines concatenated as I did in the request.

I can’t figure out how to parse that with anything at all semi-automated in Python. urllib2 and httplib both return after the first response and drop the second one on the floor.

Has anyone encountered this problem before? Does anyone know of a Python library that can handle this strange multi-request behaviour?