update for beem: handling Could not find API exceptions and other node failures

holger80(74)
Published in
#beem
Words
199
Reading
1 min
Listen
Play
7y

Repository

https://github.com/holgern/beem


beem-logo

beem is a python library for steem. The current version is 0.20.23.

There is also a discord channel for beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

pip install -U beem

Changelog

  • Switch to next node, when current node has the necesary api not enabled
  • handle Client returned invalid format. Expected JSON! and switch to next node
  • More checks added
  • get_estimated_block_num is faster and uses BlockHeader
  • exclude_limited=False is default now for get_nodes

Switching automatically to the next node on ApiNotSupported errors

At the moment, the full nodes have some problems and a lot nodes have disabled some apis. beem can now handle this and is automatically switching to the next node in the list.

from beem.account import Account
from beem import Steem
stm = Steem("https://steemd.minnowsupportproject.org")
account = Account("steemit", steem_instance=stm)
print(account.get_blog(0, 1))

returns the error:

beemapi.exceptions.ApiNotSupported: Assert Exception:api_itr != _registered_apis.end(): Could not find API follow_api

As there is only one node given, beem cannot switch to then next node.
When using a node list instead:

from beem.account import Account
from beem import Steem
from beem.nodelist import NodeList
nodelist = NodeList()
stm = Steem(node=nodelist .get_nodes())
account = Account("steemit", steem_instance=stm)
print(account.get_blog(0, 1))

the script returns:

Error: Assert Exception:api_itr != _registered_apis.end(): Could not find API follow_api
Lost connection or internal error on node: https://steemd.minnowsupportproject.org (1/100) 

[<Comment @steemit/firstpost>]

which means that first failing with https://steemd.minnowsupportproject.org, but then retrying sucessfully with https://rpc.usesteem.com.

Using update_nodes

The following nodes are currently stored in NodeList:

from beem.nodelist import NodeList
nodelist = NodeList()
print(nodelist .get_nodes())

the following nodes are returned:

['https://steemd.minnowsupportproject.org', 'https://rpc.usesteem.com', 'https://anyx.io', 'https://api.steemit.com', 'https://steemd.privex.io', 'http://anyx.io', 'https://appbasetest.timcliff.com', 'https://api.steem.house']
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
print(nodelist .get_nodes())

nodelist.update_nodes() fetches the currently working nodelist from fullnodeupdate@fullnodeupdate. I'm writing a fullnode benchmark every 3 hours to this account, which can be obtained from the json_metadata field.

Currently the following nodes are working:

['http://anyx.io', 'https://anyx.io', 'https://steemd.minnowsupportproject.org', 'https://api.steemit.com', 'https://rpc.usesteem.com', 'https://api.steem.house', 'https://steemd.privex.io']

update for beem: handling Could not find API exceptions and other n... | Ecency