def rpcConnection(): print("connecting to http://%s:%[email protected]:%i/" % (config.RPC_USER, config.RPC_PASSWORD, config.ZCASH_RPC_PORT)) rpc_connection = AuthServiceProxy( "http://%s:%[email protected]:%i/" % (config.RPC_USER, config.RPC_PASSWORD, config.ZCASH_RPC_PORT), timeout=120) rpc_connection2 = AuthServiceProxy("http://%s:%[email protected]:8331/" % (config.RPC_USER, config.RPC_PASSWORD), timeout=120) # test it count = 0 maxTries = 5 while (count < maxTries): count += 1 try: info = rpc_connection.getinfo() info2 = rpc_connection.get_info() return rpc_connection except JSONRPCException as e: print "Authentication error " + str(e) print "Exiting program " sys.exit(1) except Exception as e: # apologies for bad exception catching print("Socket error when connecting to RPC") print(e) print("Waiting 5 seconds then trying again") time.sleep(5) print("Could not establish a connection") print("Exiting") sys.exit(1)