本文整理汇总了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]
示例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
示例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)
示例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))