Fetching an external URL

Python includes the urllib library for fetching urls:

  1. import urllib
  2. page = urllib.urlopen('http://www.web2py.com').read()

This is often fine, but the urllib module does not work on the Google App Engine. Google provides a different API for downloading URLs that works on GAE only. In order to make your code portable, web2py includes a fetch function that works on GAE as well as other Python installations:

  1. from gluon.tools import fetch
  2. page = fetch('http://www.web2py.com')