Created
October 12, 2018 15:26
-
-
Save imylomylo/7bfcd4a44082386421da0082b9ebc77a to your computer and use it in GitHub Desktop.
python3 json kmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using https://jsonrpcclient.readthedocs.io/en/latest/api.html | |
sudo add-apt-repository ppa:jonathonf/python-3.6 | |
sudo apt-get update | |
sudo apt-get install python3.6 | |
sudo apt-get install python3-pip | |
pip3 install "jsonrpcclient[requests]" | |
# Start python3 | |
>>> from jsonrpcclient.clients.http_client import HTTPClient | |
>>> client = HTTPClient("http://localhost:7771/") | |
>>> client.session.auth = ("user", "pass") | |
>>> client.session.headers.update({"Content-Type": "application/json-rpc"}) | |
>>> response = client.send('{"jsonrpc": "2.0", "method": "getinfo", "id": 1}') | |
^^^^^^ Turn that into re-usable code. The line that starts with "response = client.send....." | |
you put into all of your methods re-using the client object created. | |
Sample output from and old pirate chain running follows. Looks like some error, but it's python. | |
Ask emmanuel or patchkez. | |
mylo@dedi-par-76117:~$ python3 | |
Python 3.5.2 (default, Nov 23 2017, 16:37:01) | |
[GCC 5.4.0 20160609] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from jsonrpcclient.clients.http_client import HTTPClient | |
>>> client = HTTPClient("http://localhost:45453/") | |
>>> client.session.auth = ("user793173901", "pass07e8702e5982abfee0cf32381716717941bcde8c04dbda147818d26ee94f9737d4") | |
>>> client.session.headers.update({"Content-Type": "application/json-rpc"}) | |
>>> response = client.send('{"jsonrpc": "2.0", "method": "getinfo", "id": 1}') | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/mylo/.local/lib/python3.5/site-packages/apply_defaults/decorators.py", line 13, in wrapper | |
return function(self, *args, **kwargs) | |
File "/home/mylo/.local/lib/python3.5/site-packages/jsonrpcclient/client.py", line 167, in send | |
response.text, batch=batch, validate_against_schema=validate_against_schema | |
File "/home/mylo/.local/lib/python3.5/site-packages/jsonrpcclient/parse.py", line 70, in parse | |
jsonschema.validate(deserialized, schema) | |
File "/home/mylo/.local/lib/python3.5/site-packages/jsonschema/validators.py", line 541, in validate | |
cls(schema, *args, **kwargs).validate(instance) | |
File "/home/mylo/.local/lib/python3.5/site-packages/jsonschema/validators.py", line 130, in validate | |
raise error | |
jsonschema.exceptions.ValidationError: {'error': None, 'id': 1, 'result': {'notarized_confirms': 0, 'rpcport': 45453, 'version': 1001550, 'name': 'PIRATE', 'balance': 0.0, 'p2pport': 45452, 'notarizedhash': '0000000000000000000000000000000000000000000000000000000000000000', 'longestchain': 36719, 'prevMoMheight': 0, 'relayfee': 1e-06, 'notarized': 0, 'timeoffset': 0, 'tiptime': 1537796161, 'KMDversion': '0.1.1', 'keypoololdest': 1538907055, 'paytxfee': 0.0, 'protocolversion': 170003, 'magic': 397860952, 'reward': 25600000000, 'connections': 1, 'testnet': False, 'errors': '', 'notarizedtxid': '0000000000000000000000000000000000000000000000000000000000000000', 'halving': 77777, 'keypoolsize': 101, 'KMDnotarized_height': 0, 'notarizedtxid_height': 'mempool', 'proxy': '', 'blocks': 36719, 'walletversion': 60000, 'difficulty': 5103076.631849649}} is not valid under any of the given schemas | |
Failed validating 'oneOf' in schema: | |
{'$schema': 'http://json-schema.org/draft-04/schema#', | |
'definitions': {'common': {'not': {'description': 'cannot have result ' | |
'and error at the ' | |
'same time', | |
'required': ['result', 'error']}, | |
'properties': {'id': {'note': ['spec says ' | |
'a number ' | |
'which ' | |
'should not ' | |
'contain a ' | |
'fractional ' | |
'part', | |
'We choose ' | |
'integer ' | |
'here, but ' | |
'this is ' | |
'unenforceable ' | |
'with some ' | |
'languages'], | |
'type': ['string', | |
'integer', | |
'null']}, | |
'jsonrpc': {'enum': ['2.0']}}, | |
'required': ['id', 'jsonrpc'], | |
'type': 'object'}, | |
'error': {'allOf': [{'$ref': '#/definitions/common'}, | |
{'properties': {'error': {'properties': {'code': {'note': ['unenforceable ' | |
'in ' | |
'some ' | |
'languages'], | |
'type': 'integer'}, | |
'data': {'description': 'optional, ' | |
'can ' | |
'be ' | |
'anything'}, | |
'message': {'type': 'string'}}, | |
'required': ['code', | |
'message'], | |
'type': 'object'}}, | |
'required': ['error']}]}, | |
'success': {'allOf': [{'$ref': '#/definitions/common'}, | |
{'required': ['result']}], | |
'description': 'A success. The result ' | |
'member is then required ' | |
'and can be anything.'}}, | |
'description': 'A JSON RPC 2.0 response', | |
'oneOf': [{'$ref': '#/definitions/success'}, | |
{'$ref': '#/definitions/error'}, | |
{'items': {'oneOf': [{'$ref': '#/definitions/success'}, | |
{'$ref': '#/definitions/error'}]}, | |
'type': 'array'}]} | |
On instance: | |
{'error': None, | |
'id': 1, | |
'result': {'KMDnotarized_height': 0, | |
'KMDversion': '0.1.1', | |
'balance': 0.0, | |
'blocks': 36719, | |
'connections': 1, | |
'difficulty': 5103076.631849649, | |
'errors': '', | |
'halving': 77777, | |
'keypoololdest': 1538907055, | |
'keypoolsize': 101, | |
'longestchain': 36719, | |
'magic': 397860952, | |
'name': 'PIRATE', | |
'notarized': 0, | |
'notarized_confirms': 0, | |
'notarizedhash': '0000000000000000000000000000000000000000000000000000000000000000', | |
'notarizedtxid': '0000000000000000000000000000000000000000000000000000000000000000', | |
'notarizedtxid_height': 'mempool', | |
'p2pport': 45452, | |
'paytxfee': 0.0, | |
'prevMoMheight': 0, | |
'protocolversion': 170003, | |
'proxy': '', | |
'relayfee': 1e-06, | |
'reward': 25600000000, | |
'rpcport': 45453, | |
'testnet': False, | |
'timeoffset': 0, | |
'tiptime': 1537796161, | |
'version': 1001550, | |
'walletversion': 60000}} | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment