Python google.appengine.api.urlfetch.make_fetch_call() Examples
The following are 5
code examples of google.appengine.api.urlfetch.make_fetch_call().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.api.urlfetch
, or try the search function
.
Example #1
Source File: rpc.py From python-docs-samples with Apache License 2.0 | 6 votes |
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]
Example #2
Source File: hn.py From hackernewsbot with MIT License | 5 votes |
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
Example #3
Source File: rpc.py From python-docs-samples with Apache License 2.0 | 5 votes |
def get(self): # [START urlfetch-rpc-callback] def handle_result(rpc): result = rpc.get_result() self.response.write(result.content) logging.info('Handling RPC in callback: result {}'.format(result)) urls = ['http://www.google.com', 'http://www.github.com', 'http://www.travis-ci.org'] rpcs = [] for url in urls: rpc = urlfetch.create_rpc() rpc.callback = functools.partial(handle_result, rpc) urlfetch.make_fetch_call(rpc, url) rpcs.append(rpc) # ... do other things ... # Finish all RPCs, and let callbacks process the results. for rpc in rpcs: rpc.wait() logging.info('Done waiting for RPCs') # [END urlfetch-rpc-callback]
Example #4
Source File: fetcher.py From cloud-playground with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: main.py From datastore-ndb-python with Apache License 2.0 | 4 votes |
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))