当前位置: 首页>>代码示例>>Python>>正文


Python AsyncHTTPClient.fetch方法代码示例

本文整理汇总了Python中tornado.httpclient.AsyncHTTPClient.fetch方法的典型用法代码示例。如果您正苦于以下问题:Python AsyncHTTPClient.fetch方法的具体用法?Python AsyncHTTPClient.fetch怎么用?Python AsyncHTTPClient.fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.httpclient.AsyncHTTPClient的用法示例。


在下文中一共展示了AsyncHTTPClient.fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_timelapse_movie

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
def get_timelapse_movie(local_config, key, group, callback):
    scheme, host, port, username, password, path, camera_id = _remote_params(local_config)
    
    logging.debug('downloading timelapse movie 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/?key=%(key)s' % {
            'id': camera_id,
            'group': group,
            'key': key},
            timeout=10 * settings.REMOTE_REQUEST_TIMEOUT)

    def on_response(response):
        if response.error:
            logging.error('failed to download timelapse movie 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 = AsyncHTTPClient()
    http_client.fetch(request, _callback_wrapper(on_response))
开发者ID:garyni,项目名称:motioneye,代码行数:32,代码来源:remote.py

示例2: __sweep

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
    def __sweep(self):
        """
        the function called by the cleanup service
        """
        #print 'candid: ' + str(len(self.__remove_candidates))
        self.__log.info('cleanup service - Sweep started')
        for sharing_secret in self.__remove_candidates:
            #cleanup all the listeners
            candidate = self.__remove_candidates[sharing_secret]
            #In case a lot of actions are waiting to be executed
            #and are clogged in the space, don't clean it up give it
            #a chance for another sweeping period
            if not candidate.is_being_processed():
                self.__log.info('cleanup service - cleaning candidate for %s' % sharing_secret)
                candidate.cleanup()
                #notify the load balancer of the cleanup
                http = AsyncHTTPClient()
                load_balancer = Properties.load_balancer_url
                url = '/'.join([load_balancer, 'SharingFactory',sharing_secret])
                http.fetch(url, method='DELETE', callback=None)
                #yield gen.Task(http.fetch, url, method = 'DELETE')
                #remove if from stored sharing spaces
                del(self.__sharing_spaces[sharing_secret])
            else:
                self.__log.info('cleanup service - skipping cleaning candidate for %s is being processed' % sharing_secret)


        #now nominate every one
        self.__remove_candidates.clear()
        for sharing_secret in self.__sharing_spaces:
            self.__remove_candidates[sharing_secret] = \
                self.__sharing_spaces[sharing_secret]
        self.__log.info('cleanup service - Sweep finished')
        self.timer = Timer(self.SWEEP_PERIOD, self.__sweep)
        self.timer.start()
开发者ID:Fathalian,项目名称:Mindcloud,代码行数:37,代码来源:SharingSpaceStorage.py

示例3: ExpandSearch

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
class ExpandSearch(Spiderman):
    """Expands youtube video network.
    """

    functions = 'expand'

    def search(self):

        self.done = False
        self.requests_made = 1
        self.network = {}

        # callback function parameters
        search_key = self.search_key = str(datetime.now())
        related_search = self.related_search
        client = self.client

        cb = lambda x: related_search(x, 0)

        video_ids = [str(k) for k in self.input_object['seed']]

        global pages
        global max_results

        self.http_client = AsyncHTTPClient()

        for video_id in video_ids:
            self.http_client.fetch("http://gdata.youtube.com/feeds/api/videos/{}/related?alt=jsonc&v=2".format(video_id),
                              callback=cb)
开发者ID:Martikos,项目名称:spiderman,代码行数:31,代码来源:spiderman.py

示例4: get_motion_detection

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
def get_motion_detection(camera_id, callback):
    from tornado.httpclient import HTTPRequest, AsyncHTTPClient
    
    thread_id = camera_id_to_thread_id(camera_id)
    if thread_id is None:
        error = 'could not find thread id for camera with id %s' % camera_id
        logging.error(error)
        return callback(error=error)

    url = 'http://127.0.0.1:7999/%(id)s/detection/status' % {'id': thread_id}
    
    def on_response(response):
        if response.error:
            return callback(error=utils.pretty_http_error(response))

        enabled = bool(response.body.lower().count('active'))
        
        logging.debug('motion detection is %(what)s for camera with id %(id)s' % {
                'what': ['disabled', 'enabled'][enabled],
                'id': camera_id})

        callback(enabled)

    request = HTTPRequest(url, connect_timeout=_MOTION_CONTROL_TIMEOUT, request_timeout=_MOTION_CONTROL_TIMEOUT)
    http_client = AsyncHTTPClient()
    http_client.fetch(request, callback=on_response)
开发者ID:Ethocreeper,项目名称:motioneye,代码行数:28,代码来源:motionctl.py

示例5: __init__

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
class TaskPool:
    def __init__(self, maxClients):
        self._ioloop = ioloop.IOLoop()
        self._httpClient = AsyncHTTPClient(self._ioloop, maxClients)
        self._taskNum = 0
        
    def run(self):
        self._check()
        self._ioloop.start()

    def spawn(self, request, callback, **kwargs):
        def wapped(response):
            self._taskNum -= 1
            try:
                callback(response)
            except:
                print 'spwan error:', traceback.format_exc()
                pass
                
        self._taskNum += 1
        self._httpClient.fetch(request, wapped, **kwargs)

    def _check(self):
        def callback():
            if self._taskNum == 0:
                self._ioloop.stop()

            return self._check()
                
        self._ioloop.add_callback(callback)
开发者ID:heartshare,项目名称:imagecrawler,代码行数:32,代码来源:taskpool.py

示例6: test_with_status

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
def test_with_status(e, s, a, b):
    ss = HTTPScheduler(s)
    ss.listen(0)

    client = AsyncHTTPClient()
    response = yield client.fetch('http://localhost:%d/tasks.json' %
                                  ss.port)
    out = json.loads(response.body.decode())
    assert out['total'] == 0
    assert out['processing'] == 0
    assert out['failed'] == 0
    assert out['in-memory'] == 0
    assert out['ready'] == 0
    assert out['waiting'] == 0

    L = e.map(div, range(10), range(10))
    yield _wait(L)

    client = AsyncHTTPClient()
    response = yield client.fetch('http://localhost:%d/tasks.json' %
                                  ss.port)
    out = json.loads(response.body.decode())
    assert out['failed'] == 1
    assert out['in-memory'] == 9
    assert out['ready'] == 0
    assert out['total'] == 10
    assert out['waiting'] == 0

    ss.stop()
开发者ID:LiuXiaozeeee,项目名称:distributed,代码行数:31,代码来源:test_scheduler_http.py

示例7: search

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
    def search(self, query, callback):
        def cb(response):
            # TODO: check response for errors

            data = json.load(response.buffer)
            entries = data['feed']['entry']

            results = []
            for entry in entries:
                meta = entry['media$group']

                # construct video URL (with autoplay enabled)
                video = 'https://www.youtube.com/embed/{0}?autoplay=1'.format(
                    meta['yt$videoid']['$t'])

                thumbnail = filter(lambda t: t['yt$name'] == 'default',
                    meta['media$thumbnail'])[0]
                thumbnail = thumbnail['url']

                result = SearchResult(meta['media$title']['$t'], video, self.id,
                    thumbnail)
                results.append(result)

            callback(results)

        # Youtube API documentation:
        # https://developers.google.com/youtube/2.0/developers_guide_protocol
        client = AsyncHTTPClient()
        qs = urlencode({
            'q':           query,
            'max-results': '5',
            'alt':         'json',
            'v':           '2'
        })
        client.fetch('https://gdata.youtube.com/feeds/api/videos/?' + qs, cb)
开发者ID:krmnn,项目名称:wall,代码行数:37,代码来源:__init__.py

示例8: test_simple

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
def test_simple(s, a, b):
    server = HTTPWorker(a)
    server.listen(0)
    client = AsyncHTTPClient()

    response = yield client.fetch('http://localhost:%d/info.json' % server.port)
    response = json.loads(response.body.decode())
    assert response['ncores'] == a.ncores
    assert response['status'] == a.status

    response = yield client.fetch('http://localhost:%d/resources.json' %
            server.port)
    response = json.loads(response.body.decode())

    a.data['x'] = 1

    try:
        import psutil
        assert 0 < response['memory_percent'] < 100
    except ImportError:
        assert response == {}

    endpoints = ['/files.json', '/processing.json', '/nbytes.json',
                 '/nbytes-summary.json']
    for endpoint in endpoints:
        response = yield client.fetch(('http://localhost:%d' % server.port)
                                      + endpoint)
        response = json.loads(response.body.decode())
        assert response

    server.stop()
开发者ID:amosonn,项目名称:distributed,代码行数:33,代码来源:test_worker_http.py

示例9: take_snapshot

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
def take_snapshot(camera_id):
    from tornado.httpclient import HTTPRequest, AsyncHTTPClient

    thread_id = camera_id_to_thread_id(camera_id)
    if thread_id is None:
        return logging.error('could not find thread id for camera with id %s' % camera_id)

    logging.debug('taking snapshot for camera with id %(id)s' % {'id': camera_id})

    url = 'http://127.0.0.1:%(port)s/%(id)s/action/snapshot' % {
            'port': settings.MOTION_CONTROL_PORT,
            'id': thread_id}

    def on_response(response):
        if response.error:
            logging.error('failed to take snapshot for camera with id %(id)s: %(msg)s' % {
                    'id': camera_id,
                    'msg': utils.pretty_http_error(response)})

        else:
            logging.debug('successfully took snapshot for camera with id %(id)s' % {'id': camera_id})

    request = HTTPRequest(url, connect_timeout=_MOTION_CONTROL_TIMEOUT, request_timeout=_MOTION_CONTROL_TIMEOUT)
    http_client = AsyncHTTPClient()
    http_client.fetch(request, on_response)
开发者ID:dermotduffy,项目名称:motioneye,代码行数:27,代码来源:motionctl.py

示例10: post_suggest

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
    def post_suggest(self, user_id: str, application_id: str, session_id: str, locale: str, context: dict,
                     callback) -> str:
        self.logger.debug(
            "user_id=%s,application_id=%s,session_id=%s,locale=%s,"
            "context=%s",
            user_id, application_id, session_id, locale, context
        )

        url = "%s?session_id=%s&application_id=%s&locale=%s" % (
            SUGGEST_URL, session_id, application_id, locale
        )
        url += "&user_id=%s" % user_id if user_id is not None else ""

        try:
            request_body = {
                "context": context
            }

            http_client = AsyncHTTPClient()
            http_client.fetch(HTTPRequest(url=url, body=dumps(request_body), method="POST"), callback=callback)
            http_client.close()

        except HTTPError:
            self.logger.error("url=%s", url)
            raise
开发者ID:rdefeo,项目名称:api,代码行数:27,代码来源:suggestions.py

示例11: _check_group_whitelist

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
 def _check_group_whitelist(self, username, user_id, is_admin, access_token):
     http_client = AsyncHTTPClient()
     headers = _api_headers(access_token)
     if is_admin:
         # For admins, /groups returns *all* groups. As a workaround
         # we check if we are a member of each group in the whitelist
         for group in map(url_escape, self.gitlab_group_whitelist):
             url = "%s/groups/%s/members/%d" % (GITLAB_API, group, user_id)
             req = HTTPRequest(url, method="GET", headers=headers)
             resp = yield http_client.fetch(req, raise_error=False)
             if resp.code == 200:
                 return True  # user _is_ in group
     else:
         # For regular users we get all the groups to which they have access
         # and check if any of these are in the whitelisted groups
         next_page = url_concat("%s/groups" % GITLAB_API,
                                dict(all_available=True))
         while next_page:
             req = HTTPRequest(next_page, method="GET", headers=headers)
             resp = yield http_client.fetch(req)
             resp_json = json.loads(resp.body.decode('utf8', 'replace'))
             next_page = next_page_from_links(resp)
             user_groups = set(entry["path"] for entry in resp_json)
             # check if any of the organizations seen thus far are in whitelist
             if len(self.gitlab_group_whitelist & user_groups) > 0:
                 return True
         return False
开发者ID:hydroshare,项目名称:oauthenticator,代码行数:29,代码来源:gitlab.py

示例12: on_message

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
    def on_message(self, message):
        ts = get_utc_timestamp()
        message_dict = json.loads(message)
        message_dict.update({'timestamp': ts, 'author': self.profile})
        self.redis_client.zadd(self.chat_token, ts, json.dumps(message_dict))

        message_dict.update({'token': self.chat_token})
        pika_client.sample_message(json.dumps(message_dict))

        members = self.redis_client.smembers('%s-%s' % ('members', self.chat_token))
        members.discard(self.profile['token'])

        for other in members:
            # Increase notification count for users other than sender
            self.redis_client.incr('%s-%s-%s' % (REGULAR_MESSAGE_TYPE, self.chat_token, other))

        self.redis_client.set('%s-%s-%s' % (REGULAR_MESSAGE_TYPE, self.chat_token, self.profile['token']), 0)

        if REGULAR_MESSAGE_TYPE in NOTIFIABLE_MESSAGE_TYPES:
            headers = {'Authorization': 'Token %s' % self.profile['token'], 'content-type': 'application/json'}
            [members.discard(socket.profile['token']) for socket in websockets[self.chat_token]]

            data = {
                'chat_token': self.chat_token,
                'receivers': list(members),
                'body': message_dict['body'],
                'type': REGULAR_MESSAGE_TYPE,
                'author': message_dict['author']
            }

            client = AsyncHTTPClient()
            request = HTTPRequest(PUSH_NOTIFICATION_URL, body=json.dumps(data), headers=headers, method='POST')
            client.fetch(request, callback=push_notification_callback)
开发者ID:ryr,项目名称:hipochat,代码行数:35,代码来源:chat.py

示例13: del_media_group

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
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)

    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 = AsyncHTTPClient()
    http_client.fetch(request, _callback_wrapper(on_response))
开发者ID:garyni,项目名称:motioneye,代码行数:31,代码来源:remote.py

示例14: post

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
    def post(self):

        json_str = self.get_argument("json_msg")
        # print "json_str: ",json_str
        value_obj = json.loads(json_str)

        com_val = COMMAND_URL_DICT[value_obj["command"]]
        com_url = com_val[0]
        com_func = com_val[1]
        url = "http://115.28.143.67:" + str(PORT) + com_url
        print "---------------------------------------"
        print "request url: " + url
        print "request json: " + json_str
        print "---------------------------------------"

        if "GET" == com_func:
            request = HTTPRequest(url, "GET")
            http = AsyncHTTPClient()
            response = yield http.fetch(request)
            print "---------------------------------------"
            print "response json: " + response.body
            print "---------------------------------------"
            self.write(response.body)
        elif "POST" == com_func:
            request = HTTPRequest(url, "POST", body=json_str)
            http = AsyncHTTPClient()
            response = yield http.fetch(request)
            print "---------------------------------------"
            print "response json: " + response.body
            print "---------------------------------------"
            self.write(response.body)
        else:
            pass
开发者ID:thm-tech,项目名称:forward,代码行数:35,代码来源:client.py

示例15: post

# 需要导入模块: from tornado.httpclient import AsyncHTTPClient [as 别名]
# 或者: from tornado.httpclient.AsyncHTTPClient import fetch [as 别名]
    def post(self):
        data = json_decode(self.request.body)
        logger.debug('Sonarr download: %s', data)
        event_type = data['EventType']
        if event_type in ['Test', 'Rename']:
            return

        http_client = AsyncHTTPClient()
        for episode in data['Episodes']:
            id = episode['Id']
            headers = {'X-Api-Key':env.settings.sonarr_api_key}

            request = HTTPRequest(
                method='GET', headers=headers,
                url='%s/api/Episode/%d' % (env.settings.sonarr_url, id))
            response = yield http_client.fetch(request)
            episode_data = json_decode(response.body)
            logger.debug('Sonarr episode data: %s', episode_data)

            file_id = episode_data['episodeFileId']
            request = HTTPRequest(
                method='GET', headers=headers,
                url='%s/api/EpisodeFile/%d' % (env.settings.sonarr_url, file_id))
            response = yield http_client.fetch(request)
            file_data = json_decode(response.body)
            logger.debug('Sonarr file data: %s', file_data)

            path = file_data['path']
            name = file_data['sceneName']+os.path.splitext(path)[1]
            logger.info("ADD (sonarr): %s -> %s", path, name)
            SuperliminalCore.add_video(path, name)
开发者ID:NigelRook,项目名称:superliminal,代码行数:33,代码来源:api.py


注:本文中的tornado.httpclient.AsyncHTTPClient.fetch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。