From ca67f885d44fd6f5e525f256212b335147b7407e Mon Sep 17 00:00:00 2001 From: Holger Nahrstaedt <holger@nahrstaedt.de> Date: Wed, 11 Apr 2018 08:05:59 +0200 Subject: [PATCH] Several bug fixes and small improvements --- beem/comment.py | 2 +- beem/steem.py | 9 ++++++++- beem/vote.py | 2 +- beemapi/steemnoderpc.py | 7 ++++++- beemgrapheneapi/graphenerpc.py | 8 ++++---- examples/benchmark_nodes2.py | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/beem/comment.py b/beem/comment.py index 6814dcab..88c6ff96 100644 --- a/beem/comment.py +++ b/beem/comment.py @@ -95,7 +95,7 @@ class Comment(BlockchainObject): else: content = self.steem.rpc.get_content(author, permlink) if not content or not content['author'] or not content['permlink']: - raise ContentDoesNotExistsException + raise ContentDoesNotExistsException(self.identifier) super(Comment, self).__init__(content, id_item="authorperm", steem_instance=self.steem) self["authorperm"] = construct_authorperm(self["author"], self["permlink"]) self.identifier = self["authorperm"] diff --git a/beem/steem.py b/beem/steem.py index 1a6acfdb..8271d74d 100644 --- a/beem/steem.py +++ b/beem/steem.py @@ -55,6 +55,10 @@ class Steem(object): to bundle operations *(optional)* :param bool appbase: Use the new appbase rpc protocol on nodes with version 0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower. + :param int num_retries: Set the maximum number of reconnects to the nodes before + NumRetriesReached is raised. Disabled for -1. (default is -1) + :param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5) + :param int timeout: Timeout setting for https nodes (default is 60) Three wallet operation modes are possible: @@ -126,7 +130,10 @@ class Steem(object): to bundle operations *(optional)* :param bool appbase: Use the new appbase rpc protocol on nodes with version 0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower. - :param int num_retries: Set the maximum number of reconnects to the nodes before NumRetriesReached is raised + :param int num_retries: Set the maximum number of reconnects to the nodes before + NumRetriesReached is raised. Disabled for -1. (default is -1) + :param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5) + :param int timeout: Timeout setting for https nodes (default is 60) """ self.rpc = None diff --git a/beem/vote.py b/beem/vote.py index 8ffa1650..72e88d12 100644 --- a/beem/vote.py +++ b/beem/vote.py @@ -93,7 +93,7 @@ class Vote(BlockchainObject): else: votes = self.steem.rpc.get_active_votes(author, permlink, api="database_api") except UnkownKey: - raise VoteDoesNotExistsException + raise VoteDoesNotExistsException(self.identifier) vote = None for x in votes: diff --git a/beemapi/steemnoderpc.py b/beemapi/steemnoderpc.py index 0aa94cb1..5be3cee5 100644 --- a/beemapi/steemnoderpc.py +++ b/beemapi/steemnoderpc.py @@ -17,7 +17,12 @@ log = logging.getLogger(__name__) class SteemNodeRPC(GrapheneRPC): """This class allows to call API methods exposed by the witness node via websockets / rpc-json. - + :param str urls: Either a single Websocket/Http URL, or a list of URLs + :param str user: Username for Authentication + :param str password: Password for Authentication + :param int num_retries: Try x times to num_retries to a node on disconnect, -1 for indefinitely + :param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5) + :param int timeout: Timeout setting for https nodes (default is 60) """ def __init__(self, *args, **kwargs): diff --git a/beemgrapheneapi/graphenerpc.py b/beemgrapheneapi/graphenerpc.py index 0bbcf6a2..fe552da4 100644 --- a/beemgrapheneapi/graphenerpc.py +++ b/beemgrapheneapi/graphenerpc.py @@ -56,6 +56,7 @@ class GrapheneRPC(object): :param str password: Password for Authentication :param int num_retries: Try x times to num_retries to a node on disconnect, -1 for indefinitely :param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5) + :param int timeout: Timeout setting for https nodes (default is 60) Available APIs * database @@ -163,13 +164,12 @@ class GrapheneRPC(object): if self.ws: self.ws.connect(self.url) try: + props = None props = self.get_config(api="database") except Exception as e: - if re.search("Bad Cast:Invalid cast from type", stra(e)): + if re.search("Bad Cast:Invalid cast from type", str(e)): self.current_rpc += 2 props = self.get_config(api="database") - else: - prop = None if props is None: raise RPCError("Could not recieve answer for get_config") if is_network_appbase_ready(props): @@ -255,7 +255,7 @@ class GrapheneRPC(object): self.error_cnt_call += 1 try: - if self.current_rpc == 0 or self.current_rpc == 3: + if self.current_rpc == 0 or self.current_rpc == 2: reply = self.ws_send(json.dumps(payload, ensure_ascii=False).encode('utf8')) else: reply = self.request_send(json.dumps(payload, ensure_ascii=False).encode('utf8')) diff --git a/examples/benchmark_nodes2.py b/examples/benchmark_nodes2.py index 50ee43e9..a0c6fe7a 100644 --- a/examples/benchmark_nodes2.py +++ b/examples/benchmark_nodes2.py @@ -40,7 +40,7 @@ if __name__ == "__main__": for node in nodes: print("Current node:", node) try: - stm = Steem(node=node, num_retries=2, num_retries_call=2) + stm = Steem(node=node, num_retries=2, num_retries_call=3, timeout=5) blockchain = Blockchain(steem_instance=stm) account = Account("gtg", steem_instance=stm) virtual_op_count = account.virtual_op_count() -- GitLab