當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。