monero-ecosystem / monero-python

A comprehensive Python module for handling Monero cryptocurrency
BSD 3-Clause "New" or "Revised" License
245 stars 79 forks source link

jsonrpc does not work (MethodNotFound: Method not found) #75

Closed ghost closed 3 years ago

ghost commented 3 years ago
❯ docker run --rm --net host --rm -e DAEMON_HOST=0.0.0.0 -v /home/toor/monero:/monero xmrto/monero --data-dir /monero
2020-12-29 20:04:48.920 I Monero 'Oxygen Orion' (v0.17.0.0-e5decd0cd)
2020-12-29 20:04:48.920 I Initializing cryptonote protocol...
2020-12-29 20:04:48.920 I Cryptonote protocol initialized OK
2020-12-29 20:04:48.921 I Initializing core...
2020-12-29 20:04:48.921 I Loading blockchain from folder /monero/lmdb ...
2020-12-29 20:04:48.953 I Loading checkpoints
2020-12-29 20:04:48.953 I Core initialized OK
2020-12-29 20:04:48.953 I Initializing p2p server...
2020-12-29 20:04:48.956 I p2p server initialized OK
2020-12-29 20:04:48.956 I Initializing core RPC server...
2020-12-29 20:04:48.956 I Binding on 0.0.0.0 (IPv4):28081
2020-12-29 20:04:49.431 I core RPC server initialized OK on port: 28081
2020-12-29 20:04:49.431 I Starting core RPC server...
2020-12-29 20:04:49.431 I core RPC server started ok
2020-12-29 20:04:49.431 I Starting p2p net loop...
2020-12-29 20:04:50.432 I 
2020-12-29 20:04:50.432 I **********************************************************************
2020-12-29 20:04:50.432 I The daemon will start synchronizing with the network. This may take a long time to complete.
2020-12-29 20:04:50.432 I 
2020-12-29 20:04:50.432 I You can set the level of process detailization through "set_log <level|categories>" command,
2020-12-29 20:04:50.432 I where <level> is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING).
2020-12-29 20:04:50.432 I 
2020-12-29 20:04:50.432 I Use the "help" command to see the list of available commands.
2020-12-29 20:04:50.432 I Use "help <command>" to see a command's documentation.
2020-12-29 20:04:50.432 I **********************************************************************
2020-12-29 20:04:51.450 I [39.105.109.243:18080 OUT] Sync data returned a new top block candidate: 284196 -> 2263011 [Your node is 1978815 blocks (6.1 years) behind] 
2020-12-29 20:04:51.451 I SYNCHRONIZATION started
In [2]:                                                                                                                                       
Do you really want to exit ([y]/n)? y
❯ ipython3
Python 3.6.12 (default, Dec 02 2020, 09:44:23) [GCC]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from monero.wallet import Wallet 
   ...: from monero.backends.jsonrpc import JSONRPCWallet                                                                                     

In [2]: w = Wallet(JSONRPCWallet(port=28081))                                                                                                 
JSON RPC error:
{
  "error": {
    "code": -32601,
    "message": "Method not found"
  },
  "id": 0,
  "jsonrpc": "2.0"
}
---------------------------------------------------------------------------
MethodNotFound                            Traceback (most recent call last)
<ipython-input-2-c0dbfab904dd> in <module>
----> 1 w = Wallet(JSONRPCWallet(port=28081))

~/.local/lib/python3.6/site-packages/monero/wallet.py in __init__(self, backend)
     34         self.incoming = PaymentManager(0, backend, 'in')
     35         self.outgoing = PaymentManager(0, backend, 'out')
---> 36         self.refresh()
     37 
     38     def refresh(self):

~/.local/lib/python3.6/site-packages/monero/wallet.py in refresh(self)
     45         self.accounts = self.accounts or []
     46         idx = 0
---> 47         for _acc in self._backend.accounts():
     48             _acc.wallet = self
     49             try:

~/.local/lib/python3.6/site-packages/monero/backends/jsonrpc.py in accounts(self)
    255     def accounts(self):
    256         accounts = []
--> 257         _accounts = self.raw_request('get_accounts')
    258         idx = 0
    259         self._master_address = Address(_accounts['subaddress_accounts'][0]['base_address'])

~/.local/lib/python3.6/site-packages/monero/backends/jsonrpc.py in raw_request(self, method, params, squelch_error_logging)
    505                 _log.error(u"JSON RPC error:\n{result}".format(result=_ppresult))
    506             if err['code'] in _err2exc:
--> 507                 raise _err2exc[err['code']](err['message'])
    508             else:
    509                 raise RPCError(

MethodNotFound: Method not found

In [3]:                  
ghost commented 3 years ago

starting the older tags requires a --non-interactive parameter

docker run --rm --net host --rm -e DAEMON_HOST=0.0.0.0 -v /home/toor/monero:/monero xmrto/monero:v0.15.0.1 --data-dir /monero --non-interactive
lalanza808 commented 3 years ago

Your Python code is using Wallet and JSONRPCWallet but you're interfacing with a daemon's RPC interface and not a wallet.

Try doing this instead:

from monero.daemon import Daemon
from monero.backends.jsonrpc import JSONRPCDaemon

d = Daemon(JSONRPCDaemon(port=28081))   
lalanza808 commented 3 years ago

Full example using my public node:

>>> from monero.daemon import Daemon
>>> from monero.backends.jsonrpc import JSONRPCDaemon
>>> d = Daemon(JSONRPCDaemon(host='singapore.node.xmr.pm', port=18089))
>>> d
<monero.daemon.Daemon object at 0x1086fd910>
>>> dir(d)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_backend', 'block', 'headers', 'height', 'info', 'mempool', 'net', 'send_transaction', 'transactions']
>>> d.height()
2263032
>>> d.info()
{'adjusted_time': 1609273687, 'alt_blocks_count': 0, 'block_size_limit': 600000, 'block_size_median': 300000, 'block_weight_limit': 600000, 'block_weight_median': 300000, 'bootstrap_daemon_address': '', 'credits': 0, 'cumulative_difficulty': 81109858841735165, 'cumulative_difficulty_top64': 0, 'database_size': 102005473280, 'difficulty': 208944363243, 'difficulty_top64': 0, 'free_space': 18446744073709551615, 'grey_peerlist_size': 0, 'height': 2263032, 'height_without_bootstrap': 0, 'incoming_connections_count': 0, 'mainnet': True, 'nettype': 'mainnet', 'offline': False, 'outgoing_connections_count': 0, 'rpc_connections_count': 0, 'stagenet': False, 'start_time': 0, 'status': 'OK', 'target': 120, 'target_height': 2263022, 'testnet': False, 'top_block_hash': 'bc3601a4f8c86b869e2df9aba982c5ba346717ecb9f0c014517c6632dc0cf4e4', 'top_hash': '', 'tx_count': 10610334, 'tx_pool_size': 18, 'untrusted': False, 'update_available': False, 'version': '', 'was_bootstrap_ever_used': False, 'white_peerlist_size': 0, 'wide_cumulative_difficulty': '0x12028fca40b2ffd', 'wide_difficulty': '0x30a60df6eb'}
ghost commented 3 years ago

yes I figured that out thanks, but it was really unclear, but I figured it out by chance. The only reason I figured it out is because it caught my eye, out of all of the other snowflakes on this page: https://hub.docker.com/r/xmrto/monero/

I can't do anything with python-monero now though because of another problem with monero-wallet-rpc: https://github.com/monero-project/monero/issues/7227

ghost commented 3 years ago

I confirmed that I am also able to get the daemons up and running with monerod v 0.15 and connect to them as the documentation suggests. I'm helping someone with another problem though that is similarly vague, should maybe think a little about creating some custom exception classes and making use of them if people are actually going to be using this, for what that's worth, I'm not really sure who all uses this library.

lalanza808 commented 3 years ago

@emesik this can be closed.