예제 #1
0
 async def init_client(self):
     self.session = ClientSession(loop=self.loop)
     self.api_client = AiohttpClient(
         self.session,
         self.endpoint,
         ssl=context
     )
예제 #2
0
    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)
예제 #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)
예제 #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)
예제 #5
0
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
예제 #6
0
    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
예제 #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}")
예제 #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
예제 #9
0
    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)
예제 #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)