예제 #1
0
 async def do_get(self, url="/labels"):
     url = 'https://' + self.target_host + url
     network = Network.get_instance()
     proxy = network.proxy if network else None
     async with make_aiohttp_session(proxy) as session:
         async with session.get(url) as result:
             return await result.json()
예제 #2
0
 def send_request(self, method, relative_url, data=None, *, timeout=None):
     network = Network.get_instance()
     if not network:
         raise ErrorConnectingServer('You are offline.')
     url = urljoin(self.base_url, relative_url)
     if self.debug:
         self.logger.debug(f'<-- {method} {url} {data}')
     headers = {}
     if self.user_agent:
         headers['user-agent'] = self.user_agent
     try:
         if method == 'get':
             response = Network.send_http_on_proxy(method, url,
                                                   params=data,
                                                   headers=headers,
                                                   on_finish=self.handle_response,
                                                   timeout=timeout)
         elif method == 'post':
             response = Network.send_http_on_proxy(method, url,
                                                   json=data,
                                                   headers=headers,
                                                   on_finish=self.handle_response,
                                                   timeout=timeout)
         else:
             assert False
     except TrustedCoinException:
         raise
     except Exception as e:
         raise ErrorConnectingServer(e)
     else:
         if self.debug:
             self.logger.debug(f'--> {response}')
         return response
예제 #3
0
 async def do_post(self, url="/labels", data=None):
     url = 'https://' + self.target_host + url
     network = Network.get_instance()
     proxy = network.proxy if network else None
     async with make_aiohttp_session(proxy) as session:
         async with session.post(url, json=data) as result:
             try:
                 return await result.json()
             except Exception as e:
                 raise Exception('Could not decode: ' +
                                 await result.text()) from e