Esempio n. 1
0
    async def request(self, req: BxJsonRpcRequest):
        headers = {
            rpc_constants.CONTENT_TYPE_HEADER_KEY: ContentType.JSON.value
        }

        async with ClientSession() as session:
            async with session.post(self.rpc_url,
                                    data=req.to_jsons(),
                                    headers=headers) as response:
                return JsonRpcResponse.from_json(await response.json())
Esempio n. 2
0
    async def request(self, req: BxJsonRpcRequest):
        headers = {
            rpc_constants.CONTENT_TYPE_HEADER_KEY:
            ContentType.JSON.value,
            rpc_constants.AUTHORIZATION_HEADER_KEY:
            base64.b64encode(f"{self.rpc_user}:{self.rpc_password}".encode(
                "utf-8")).decode("utf-8")
        }

        async with ClientSession() as session:
            async with session.post(self.rpc_url,
                                    data=req.to_jsons(),
                                    headers=headers) as response:
                return JsonRpcResponse.from_json(await response.json())
    async def request(self, req: BxJsonRpcRequest):
        headers = dict()
        headers[rpc_constants.CONTENT_TYPE_HEADER_KEY] = rpc_constants.PLAIN_HEADER_TYPE
        headers[rpc_constants.AUTHORIZATION_HEADER_KEY] = base64.b64encode(
                f"{self.rpc_user}:{self.rpc_password}".encode("utf-8")
            ).decode("utf-8")

        async with ClientSession() as session:
            async with session.post(
                self.rpc_url,
                data=req.to_jsons(),
                headers=headers
            ) as response:
                return JsonRpcResponse.from_jsons(await response.json())
Esempio n. 4
0
 async def request(self, req: BxJsonRpcRequest) -> JsonRpcResponse:
     async with websockets.unix_connect(self.ipc_path) as ws:
         await ws.send(req.to_jsons())
         return JsonRpcResponse.from_jsons(await ws.recv())
Esempio n. 5
0
 async def request(self, req: BxJsonRpcRequest) -> JsonRpcResponse:
     async with websockets.connect(self.ws_uri) as ws:
         await ws.send(req.to_jsons())
         response = await ws.recv()
         return JsonRpcResponse.from_jsons(response)