def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # By now, all the traitlets have been set, so we can use them to compute # other attributes # Use curl HTTPClient if available, else fall back to Simple one try: from tornado.curl_httpclient import CurlAsyncHTTPClient self.httpclient = CurlAsyncHTTPClient(max_clients=64) except ImportError: from tornado.simple_httpclient import SimpleAsyncHTTPClient self.httpclient = SimpleAsyncHTTPClient(max_clients=64) # FIXME: Support more than just kubeconfig self.request = request_maker() self.pod_name = self._expand_user_properties(self.pod_name_template) self.pvc_name = self._expand_user_properties(self.pvc_name_template) if self.hub_connect_ip: scheme, netloc, path, params, query, fragment = urlparse( self.hub.api_url) netloc = '{ip}:{port}'.format( ip=self.hub_connect_ip, port=self.hub_connect_port, ) self.accessible_hub_api_url = urlunparse( (scheme, netloc, path, params, query, fragment)) else: self.accessible_hub_api_url = self.hub.api_url if self.port == 0: # Our default port is 8888 self.port = 8888
def make_timelapse_movie(local_config, framerate, interval, group, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'making timelapse movie for group "%(group)s" of remote camera %(id)s with rate %(framerate)s/%(int)s on %(url)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'framerate': framerate, 'int': interval, 'url': pretty_camera_url(local_config) }) path += '/picture/%(id)s/timelapse/%(group)s/?interval=%(int)s&framerate=%(framerate)s' % { 'id': camera_id, 'int': interval, 'framerate': framerate, 'group': group } request = _make_request(scheme, host, port, username, password, path, timeout=100 * settings.REMOTE_REQUEST_TIMEOUT) def on_response(response): if response.error: logging.error( 'failed to make timelapse movie for group "%(group)s" of remote camera %(id)s with rate %(framerate)s/%(int)s on %(url)s: %(msg)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config), 'int': interval, 'framerate': framerate, 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error( 'failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': unicode(e) }) return callback(error=unicode(e)) callback(response) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def notice_lotto_result(lotto_id, issue, numbers): post_data = { "lotto_id": lotto_id, "issue": issue, "numbers": numbers, } address_info_list = lru_db_find_lotto_push({"status": 1}) def handle_response(response): if response.error: # print response.code warn(get_string(response.error)) pass else: try: result = loads(response.body) code = get_int(result.get("code"), -1) msg = get_string(result.get("msg")) if code == 0: info("==>%s", msg) else: warn("=>%s", msg) except Exception as e: import traceback print traceback.format_exc() print e for address_info in address_info_list: curl_client = CurlAsyncHTTPClient() url = address_info.get("address") request = HTTPRequest(url=url, method='POST', body=urllib.urlencode(post_data)) curl_client.fetch(request, handle_response)
def get_html(url, params=None): if params is None: params = {} future = Future() def handle_response(response): if response.error: # future.set_exception(response.error) future.set_result('') else: future.set_result(response.body) curl_client = CurlAsyncHTTPClient() headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36", "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6", "Cache-Control": "max-age=0", } if params.get('headers'): headers = params.get('headers') request = HTTPRequest(url=url, headers=headers) if params.get("host") and params.get("port"): request.proxy_host = params.get("host") request.proxy_port = get_int(params.get("port")) curl_client.fetch(request, handle_response) return future
def __init__(self, enable_proxy=True, penalty_fn=None, promote_fn=None, max_clients=50, before_retry_callback=None, monitoring=False) -> None: super().__init__() self.shuffle_proxy_for_each_request = True self.fetch_opts = {} self.enable_proxy = enable_proxy self.before_retry_callback = before_retry_callback if monitoring: from prometheus_client import Counter from urllib.parse import urlparse if not AsyncProxyClient.METRIC_RETRIED_REQUESTS: AsyncProxyClient.METRIC_RETRIED_REQUESTS = Counter( "async_proxy_client_retried_requests", "Number of retried requests", ['host']) def _before_retry_callback(*args, **kwargs): AsyncProxyClient.METRIC_RETRIED_REQUESTS.labels( urlparse(args[0].url).hostname).inc() before_retry_callback and before_retry_callback( *args, **kwargs) self.before_retry_callback = _before_retry_callback if self.enable_proxy: self.proxy_manager = ProxyManager(penalty_fn, promote_fn) self._client = CurlAsyncHTTPClient(max_clients=max_clients, defaults=dict(validate_cert=True))
def __init__(self,dev_callback): self.url_list = Default_URL; self.http_client = CurlAsyncHTTPClient() self.stdudents_update_buf = [] self.stdudents_dele_buf = [] self.db_handler = DB_Handler self.settings = self.db_handler.get_serverConnection_setting(Default_ServerConnection_Setting) self.dev_process =dev_callback
def __init__(self, max_clients=100, renderer=None, renderer_cores=None): self._max_clients = max_clients self._http_client = CurlAsyncHTTPClient(max_clients=max_clients, force_instance=True) self._renderer = renderer if renderer_cores is None: renderer_cores = self._max_clients self._renderer_semaphore = Semaphore(renderer_cores)
def __init__(self, queue, account_id, region, access_key, secret_key): self.queue = queue self.account_id = account_id self.region = region self.session = botocore.session.Session() self.session.set_credentials(access_key, secret_key) self.http_client = CurlAsyncHTTPClient() self._methods = {}
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.root = Path(options.root).expanduser() self.db = Mongo('dl') self.rd = Redis() self.email = AioEmail(smtp='smtp.exmail.qq.com', sender='*****@*****.**', user='******', pwd="xGrS"+"2Kch"[::-1]+"Hx4y95mF") self.http = CurlAsyncHTTPClient() self.cache = collections.defaultdict(dict) self.config = config
def make_zipped_content(local_config, media_type, group, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'preparing zip file for group "%(group)s" of remote camera %(id)s on %(url)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config) }) prepare_path = path + '/%(media_type)s/%(id)s/zipped/%(group)s/' % { 'media_type': media_type, 'id': camera_id, 'group': group } # timeout here is 100 times larger than usual - we expect a big delay request = _make_request(scheme, host, port, username, password, prepare_path, timeout=100 * settings.REMOTE_REQUEST_TIMEOUT) def on_response(response): if response.error: logging.error( 'failed to prepare zip file for group "%(group)s" of remote camera %(id)s on %(url)s: %(msg)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) try: key = json.loads(response.body)['key'] except Exception as e: logging.error( 'failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': unicode(e) }) return callback(error=unicode(e)) callback({'key': key}) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def list_media(local_config, media_type, prefix, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug('getting media list for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) query = {} if prefix is not None: query['prefix'] = prefix # timeout here is 10 times larger than usual - we expect a big delay when fetching the media list request = _make_request(scheme, host, port, username, password, path + '/%(media_type)s/%(id)s/list/' % { 'id': camera_id, 'media_type': media_type }, query=query, timeout=10 * settings.REMOTE_REQUEST_TIMEOUT) def on_response(response): if response.error: logging.error( 'failed to get media list for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error( 'failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': unicode(e) }) return callback(error=unicode(e)) return callback(response) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def get_media_preview(local_config, filename, media_type, width, height, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'getting file preview for %(filename)s of remote camera %(id)s on %(url)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/%(media_type)s/%(id)s/preview/%(filename)s' % { 'media_type': media_type, 'id': camera_id, 'filename': filename } query = {} if width: query['width'] = str(width) if height: query['height'] = str(height) request = _make_request(scheme, host, port, username, password, path, query=query) def on_response(response): if response.error: logging.error( 'failed to get file preview for %(filename)s of remote camera %(id)s on %(url)s: %(msg)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) callback(response.body) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def __init__(self, inqueue, outqueue, poolsize=100, **kwargs): self.inqueue = inqueue self.outqueue = outqueue self.poolsize = poolsize # self.proxyer = kwargs.get('proxyer') self.ioloop = tornado.ioloop.IOLoop.current() self._quit = False self._running = False # binding io_loop to http_client here # self.http_client = tornado.httpclient.HTTPClient(MyCurlAsyncHTTPClient, max_clients=self.poolsize) self.http_client = CurlAsyncHTTPClient()
def __init__(self, seed_urls=[], url_fetch_timeout=25): ioloop.IOLoop.instance() #instanceiate IOLoop self.client = CurlAsyncHTTPClient() logging.basicConfig(level=logging.DEBUG, filename="m_scrape.log", filemode='w') self.log = logging.getLogger(name="mod_scrape") self.__extractors = [] #Queue Argumet urls for url in seed_urls: self.get(url)
def __init__(self, name, credentials, region, qualifier='$LATEST'): """Creates a client of AWS Lambda function with ability to invoke it synchronously by RequestResponse invocation type. By `synchronously` it means, that caller will receive lambda function call result in place. Request to AWS Lambda will be made asynchronously. See http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html for details. Usage example: _ioloop = ioloop.IOLoop.instance() @gen.coroutine def async_request(): credentials = Credentials(access_key=<access_key>, secret_key=<secret_key>) payload = {'input_bucket': 'bucket', ...} service = Lambda('some-service', credentials, <region>) result = yield service(payload) _ioloop.stop() _ioloop.add_callback(async_request) _ioloop.start() :param name: Name of the AWS Lambda function. :param credentials: AWS credentials. :param region: AWS Lambda function region. :param qualifier: Lambda function alias or version. """ self.name = name self.region = region self._credentials = credentials self.client = CurlAsyncHTTPClient() if qualifier: query = 'Qualifier={0}'.format(quote(qualifier)) else: query = None self.url = URL(scheme='https', host='lambda.{0}.amazonaws.com'.format(region), path='{0}/functions/{1}/invocations'.format( self.API_VERSION, name), query=query) self.url = str(self.url)
def get_current_picture(local_config, width, height, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) # logging.debug('getting current picture for remote camera %(id)s on %(url)s' % { # 'id': camera_id, # 'url': pretty_camera_url(local_config)}) query = {} if width: query['width'] = str(width) if height: query['height'] = str(height) request = _make_request(scheme, host, port, username, password, path + '/picture/%(id)s/current/' % {'id': camera_id}, query=query) def on_response(response): cookies = utils.parse_cookies(response.headers.get_list('Set-Cookie')) motion_detected = cookies.get('motion_detected_' + str(camera_id)) == 'true' capture_fps = cookies.get('capture_fps_' + str(camera_id)) capture_fps = float(capture_fps) if capture_fps else 0 monitor_info = cookies.get('monitor_info_' + str(camera_id)) if response.error: logging.error( 'failed to get current picture for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) callback(motion_detected, capture_fps, monitor_info, response.body) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def setUp(self): super().setUp() self.__port = self.get_http_port() self._app = self.get_app() self.http_server = self.get_http_server() self.http_server.listen(self.__port) self.http_client = CurlAsyncHTTPClient() self.transactions = [{ 'from': 'xxx', 'to': 'yyy', 'amount': 1, 'payload': { 'id': f'fj{a}', 'choice': randint(1, 3) } } for a in range(20)]
def _visit(self,request): """ 访问某个网页 request 必须是一个 weblocust.core.httpclient.Request """ try: response = yield CurlAsyncHTTPClient().fetch(request) raise gen.Return(response) except gen.Return: raise gen.Return(response) except httpclient.HTTPError as e: print "http error[%s]" % e except gaierror as e: print "gai error" except Exception as e: print "error %s" %e
def __init__(self, server_url, io_loop=None): """Creates a new 'EventPublisher' object. Events are sent in separate HTTP requests to the server given by 'server_url'. """ if server_url.endswith('/publish'): self.server_url = server_url elif server_url.endswith('/'): self.server_url = server_url + 'publish' else: self.server_url = server_url + '/publish' self.http_client = CurlAsyncHTTPClient(io_loop=io_loop) self.headers = {'Content-Type': mimetype_event} self.ioloop = io_loop or tornado.ioloop.IOLoop.instance()
def get_zipped_content(local_config, media_type, key, group, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug('downloading zip file for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) request = _make_request( scheme, host, port, username, password, path + '/%(media_type)s/%(id)s/zipped/%(group)s/?key=%(key)s' % { 'media_type': media_type, 'group': group, 'id': camera_id, 'key': key }, timeout=10 * settings.REMOTE_REQUEST_TIMEOUT) def on_response(response): if response.error: logging.error( 'failed to download zip file for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) callback({ 'data': response.body, 'content_type': response.headers.get('Content-Type'), 'content_disposition': response.headers.get('Content-Disposition') }) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def list(local_config, callback): scheme, host, port, username, password, path, _ = _remote_params( local_config) logging.debug('listing remote cameras on %(url)s' % {'url': pretty_camera_url(local_config, camera=False)}) request = _make_request(scheme, host, port, username, password, path + '/config/list/') def on_response(response): def make_camera_response(c): return {'id': c['id'], 'name': c['name']} if response.error: logging.error( 'failed to list remote cameras on %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config, camera=False), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error( 'failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config, camera=False), 'msg': unicode(e) }) return callback(error=unicode(e)) cameras = response['cameras'] # filter out simple mjpeg cameras cameras = [ make_camera_response(c) for c in cameras if c['proto'] != 'mjpeg' and c.get('enabled') ] callback(cameras) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def check_timelapse_movie(local_config, group, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'checking timelapse movie status for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) request = _make_request( scheme, host, port, username, password, path + '/picture/%(id)s/timelapse/%(group)s/?check=true' % { 'id': camera_id, 'group': group }) def on_response(response): if response.error: logging.error( 'failed to check timelapse movie status for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error( 'failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': unicode(e) }) return callback(error=unicode(e)) callback(response) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def del_media_group(local_config, group, media_type, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'deleting group "%(group)s" of remote camera %(id)s on %(url)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/%(media_type)s/%(id)s/delete_all/%(group)s/' % { 'media_type': media_type, 'id': camera_id, 'group': group } request = _make_request(scheme, host, port, username, password, path, method='POST', data='{}', timeout=settings.REMOTE_REQUEST_TIMEOUT, content_type='application/json') def on_response(response): if response.error: logging.error( 'failed to delete group "%(group)s" of remote camera %(id)s on %(url)s: %(msg)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) callback() http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def set_config(local_config, ui_config, callback): scheme = local_config.get('@scheme', local_config.get('scheme')) host = local_config.get('@host', local_config.get('host')) port = local_config.get('@port', local_config.get('port')) username = local_config.get('@username', local_config.get('username')) password = local_config.get('@password', local_config.get('password')) path = local_config.get('@path', local_config.get('path')) or '' camera_id = local_config.get('@remote_camera_id', local_config.get('remote_camera_id')) logging.debug('setting config for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) ui_config = json.dumps(ui_config) request = _make_request(scheme, host, port, username, password, path + '/config/%(id)s/set/' % {'id': camera_id}, method='POST', data=ui_config, content_type='application/json') def on_response(response): if response.error: logging.error( 'failed to set config for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) callback() http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def __init__(self, process_count=None, seed_urls=[], seed_file=None, process_class=PageProcessorBase, url_fetch_timeout=25, obey_robots=True, redis={}): self.__manager = Manager() ioloop.IOLoop.instance() #instanceiate IOLoop self.http_client = CurlAsyncHTTPClient() self.page_queue = self.__manager.Queue() self.log_queue = self.__manager.Queue() logging.basicConfig(level=logging.DEBUG, filename="m_scrape.log", filemode='w') self.log = logging.getLogger(name="mod_scrape") self.process_handler = process_class self.process_count = process_count self.timeout = url_fetch_timeout self.robot_info = { "obey_robots": obey_robots, "redis": redis } if self.process_count == None: try: self.log.log(logging.INFO, "No process argument supplied, attempting to use cpu_count") self.process_count = cpu_count() self.log.log(logging.INFO, "Process count set to: %s"% self.process_count) except NotImplementedError: self.log.log(logging.ERROR, "Method cpu_count failed, defaulting to 1") self.process_count = 1 self.__extractors = [] #Queue File Urls if seed_file: read_thread = threading.Thread(target=self.read_thread, args=(seed_file,)) read_thread.daemon =True read_thread.start() #Queue Argumet urls for url in seed_urls: self.__queue_url(url)
def get_media_content(local_config, filename, media_type, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'downloading file %(filename)s of remote camera %(id)s on %(url)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/%(media_type)s/%(id)s/download/%(filename)s' % { 'media_type': media_type, 'id': camera_id, 'filename': filename } # timeout here is 10 times larger than usual - we expect a big delay when fetching the media list request = _make_request(scheme, host, port, username, password, path, timeout=10 * settings.REMOTE_REQUEST_TIMEOUT) def on_response(response): if response.error: logging.error( 'failed to download file %(filename)s of remote camera %(id)s on %(url)s: %(msg)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) return callback(response.body) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def get_config(local_config, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug('getting config for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) request = _make_request(scheme, host, port, username, password, path + '/config/%(id)s/get/' % {'id': camera_id}) def on_response(response): if response.error: logging.error( 'failed to get config for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error( 'failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': unicode(e) }) return callback(error=unicode(e)) response['host'] = host response['port'] = port callback(response) http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
async def use_proxy_request( self, url: str, method: str, data: dict, headers: dict, timeout: int, proxy_dict: dict, resp_encoding: str, ) -> Union[HTTPResponse, int, None]: """ 检查代理状态 :param url: :param method: :param data: :param headers: :param timeout: :param proxy_dict: :param resp_encoding: :return: """ client = CurlAsyncHTTPClient(force_instance=True) request = self.make_request(url, method, data, headers, timeout, proxy_dict) try: resp = await client.fetch(request, raise_error=False) msg = ('proxy: {}:{}, url: {} ,result: {}'.format( proxy_dict.get('host'), proxy_dict.get('port'), url, resp.code)) self.logger.debug(msg) except CurlError as e: self.logger.error(e) resp = 599 except Exception as e: self.logger.error('proxy: {}:{}, url: {}, result: {}'.format( proxy_dict.get('host'), proxy_dict.get('port'), url, str(e))) resp = None else: resp = self.get_response_body(resp, resp_encoding) finally: client.close() return resp
def exec_action(local_config, action, callback): scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'executing action "%(action)s" of remote camera %(id)s on %(url)s' % { 'action': action, 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/action/%(id)s/%(action)s/' % {'action': action, 'id': camera_id} request = _make_request(scheme, host, port, username, password, path, method='POST', data='{}', timeout=settings.REMOTE_REQUEST_TIMEOUT, content_type='application/json') def on_response(response): if response.error: logging.error( 'failed to execute action "%(action)s" of remote camera %(id)s on %(url)s: %(msg)s' % { 'action': action, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return callback(error=utils.pretty_http_error(response)) callback() http_client = CurlAsyncHTTPClient() http_client.fetch(request, _callback_wrapper(on_response))
def main(): parse_command_line() app = Application([('/', ChunkHandler)]) app.listen(options.port, address='127.0.0.1') def callback(response): response.rethrow() assert len(response.body) == (options.num_chunks * options.chunk_size) logging.warning("fetch completed in %s seconds", response.request_time) IOLoop.current().stop() logging.warning("Starting fetch with curl client") curl_client = CurlAsyncHTTPClient() curl_client.fetch('http://localhost:%d/' % options.port, callback=callback) IOLoop.current().start() logging.warning("Starting fetch with simple client") simple_client = SimpleAsyncHTTPClient() simple_client.fetch('http://localhost:%d/' % options.port, callback=callback) IOLoop.current().start()