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


Python urlfetch.make_fetch_call方法代码示例

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


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

示例1: get

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import make_fetch_call [as 别名]
def get(self):
        # [START urlfetch-rpc]
        rpc = urlfetch.create_rpc()
        urlfetch.make_fetch_call(rpc, 'http://www.google.com/')

        # ... do other things ...
        try:
            result = rpc.get_result()
            if result.status_code == 200:
                text = result.content
                self.response.write(text)
            else:
                self.response.status_int = result.status_code
                self.response.write('URL returned status code {}'.format(
                    result.status_code))
        except urlfetch.DownloadError:
            self.response.status_int = 500
            self.response.write('Error fetching URL')
        # [END urlfetch-rpc] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:21,代码来源:rpc.py

示例2: call_method_async

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import make_fetch_call [as 别名]
def call_method_async(method, callback):
  rpc = urlfetch.create_rpc(deadline=10)
  rpc.callback = create_callback(rpc, callback)
  urlfetch.make_fetch_call(rpc, BASE_URL.format(method=method))
  return rpc 
开发者ID:phil-r,项目名称:hackernewsbot,代码行数:7,代码来源:hn.py

示例3: __init__

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import make_fetch_call [as 别名]
def __init__(self, url, url_auth_suffix='', follow_redirects=False,
               headers=None):
    if headers is None:
      headers = {}
    self.url = url
    self.response = None
    self.etag, self.response_content = model.GetResource(url)
    if self.etag:
      headers['If-None-Match'] = '{}'.format(self.etag)
    self.rpc = urlfetch.create_rpc()
    full_url = '{}{}'.format(url, url_auth_suffix)
    # shared.i('urlfetch.make_fetch_call {} {}'.format(headers, full_url))
    urlfetch.make_fetch_call(self.rpc, full_url, headers=headers,
                             follow_redirects=follow_redirects,
                             validate_certificate=True) 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:17,代码来源:fetcher.py

示例4: _hp_callback

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import make_fetch_call [as 别名]
def _hp_callback(self, message):
    nickname = 'Anonymous'
    if message.userid:
      nickname = yield get_nickname(message.userid)
    # Check if there's an URL.
    body = message.body
    m = re.search(r'(?i)\bhttps?://\S+[^\s.,;\]\}\)]', body)
    if not m:
      escbody = cgi.escape(body)
    else:
      url = m.group()
      pre = body[:m.start()]
      post = body[m.end():]
      title = ''
      key = ndb.Key(flat=[UrlSummary.GetKind(), url])
      summary = yield key.get_async()
      if not summary or summary.when < time.time() - UrlSummary.MAX_AGE:
        rpc = urlfetch.create_rpc(deadline=0.5)
        urlfetch.make_fetch_call(rpc, url, allow_truncated=True)
        t0 = time.time()
        result = yield rpc
        t1 = time.time()
        logging.warning('url=%r, status=%r, dt=%.3f',
                        url, result.status_code, t1 - t0)
        if result.status_code == 200:
          bodytext = result.content
          m = re.search(r'(?i)<title>([^<]+)</title>', bodytext)
          if m:
            title = m.group(1).strip()
          summary = UrlSummary(key=key, url=url, title=title,
                               when=time.time())
          yield summary.put_async()
      hover = ''
      if summary.title:
        hover = ' title="%s"' % summary.title
      escbody = (cgi.escape(pre) +
                 '<a%s href="%s">' % (hover, cgi.escape(url)) +
                 cgi.escape(url) + '</a>' + cgi.escape(post))
    text = '%s - %s - %s<br>' % (cgi.escape(nickname),
                                 time.ctime(message.when or 0),
                                 escbody)
    if message.when is None:
      message.when = 0
    raise ndb.Return((-message.when, text)) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:46,代码来源:main.py


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