internally fetch() calls urllib if you're not on GAE:
def fetch(url):
try:
from google.appengine.api.urlfetch import fetch
if url.find('?') >= 0:
(url, payload) = url.split('?')
return fetch(url, payload=payload).content
return fetch(url).content
except:
import urllib
return urllib.urlopen(url).read()
On Sep 15, 7:09 am, Wes James <[email protected]> wrote:
> On Mon, Sep 14, 2009 at 1:54 PM, mdipierro <[email protected]> wrote:
>
> > import urllib
>
> > html=urllib.urlopen(URL(.....)).read()
>
> > On Sep 14, 2:47 pm, "V. K" <[email protected]> wrote:
> >> Hi,
>
> >> I want to call a web2py web service from the shell and obtain the HTML
> >> response (not using a web browser).
> >> From example:
>
> >> For the service:http://www....../a/c/f/x/y?z=t
>
> >> Construct the URL object:
>
> >> URL('a','c','f',args=['x','y'],vars = dict(z='t'))
>
> >> and then how do I call the controller using this object to obtain the
> >> response HTML?
>
> I just happened to stumble on this at the bottom of:
>
> http://web2py.com/examples/default/tools
>
> ---------------------------------------------------
>
> Fetch a URL
>
> The Python module urllib does not work well on the Google App Engine.
> For this reason we created a portable function for fetching url that
> works everywhere, including GAE:
>
> from gluon.tools import fetch
> html = fetch("http://www.web2py.com")
>
> ----------------------------------------------------
>
> -wes
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---