async def init_client(self):
     self.session = ClientSession(loop=self.loop)
     self.api_client = AiohttpClient(
         self.session,
         self.endpoint,
         ssl=context
     )
    def __init__(self, endpoint):
        self.endpoint = endpoint

        self.loop = asyncio.get_event_loop()
        self.session = ClientSession(loop=self.loop)
        self.api_client = AiohttpClient(self.session,
                                        self.endpoint,
                                        ssl=context)
Exemple #3
0
async def main(loop):
    async with aiohttp.ClientSession(loop=loop) as session:
        client = AiohttpClient(session, "http://localhost:5000")
        response = await client.request("ping")
    if response.data.ok:
        print(response.data.result)
    else:
        logging.error(response.data.message)
Exemple #4
0
async def main(loop):

    async with aiohttp.ClientSession(loop=loop) as session:
        client = AiohttpClient(session, "http://localhost:5000")
        requests = [Request("ping"), Request("ping"), Request("ping")]
        response = await client.send(requests)

    for data in response.data:
        if data.ok:
            print("{}: {}".format(data.id, data.result))
        else:
            logging.error("%d: %s", data.id, data.message)
async def request_async(url: str, method: str, params: dict = None):
    if not params:
        params = {}

    async with aiohttp.ClientSession() as session:
        client = AiohttpClient(session, url)
        try:
            response = await client.request(method, **params)
        except:
            raise
        else:
            return response.data.result
    async def _call_async_jsonrpc(self, target: str, method: RestMethod,
                                  params: Optional[NamedTuple], timeout: int):
        url = self._create_jsonrpc_url(target, method)
        async with ClientSession() as session:
            http_client = AiohttpClient(session, url, timeout=timeout)
            request = self._create_jsonrpc_params(method, params)

            response: Response = await http_client.send(request)

        if isinstance(response.data, list):
            raise NotImplementedError(
                f"Received batch response. Data: {response.data}")
        else:
            return response.data.result
Exemple #7
0
    async def do_pow(self, session, block):
        self.rpc_client = AiohttpClient(session, self.args.proxy, basic_logging=True)

        self.block = block
        self.pow_end_time = time.time() + self.args.pow

        waiting = random.randrange(1, 5)
        self.log("=" * 40)
        self.log(f"starting in {waiting} seconds ......")
        await asyncio.sleep(waiting)

        work = self.create_work()

        self.log(f"Start Shard PoW at block {self.block}")
        await self.start_pow(work, self.args.diff)

        self.log(f"Start DS PoW at block {self.block}")
        await self.start_pow(work, self.args.ds_diff)

        self.log(f"Pow Done at block {self.block}")
Exemple #8
0
 async def request_coroutine():
     async with aiohttp.ClientSession(auth=auth) as session:
         server = AiohttpClient(session, server_url, timeout=timeout)
         f = getattr(server, endpoint)
         response = await f(*args)
         return response.data.result
    def _init_client(self):

        loop = asyncio.get_event_loop()
        aiohttp_session = aiohttp.ClientSession(loop=loop,
                                                headers=self._get_headers())
        return AiohttpClient(aiohttp_session, self._endpoint_url, timeout=10)
Exemple #10
0
async def main(loop):
    async with aiohttp.ClientSession(loop=loop) as session:
        client = AiohttpClient(session, "http://localhost:5000")
        response = await client.request("ping")
    print(response.data.result)