Tuesday, August 5, 2008

An alternative for urllib.urlopen in Google App Engine

It took me a little searching to find out that there is a alternative for the disabled urllib.urlopen function (due to its usage of socket) in Google App Engine. It lies in google.appengine.api. The following illustrates the way to use it with the equal code using urllib.urlopen commented.
# import urllib from google.appengine.api import urlfetch # result = urllib.urlopen('http://DaNmarner.blogspot.com') result = urlfetch.fetch('http://DaNmarner.blogspot.com') # do_something_with(result.read()) do_something_with(result.content)

No comments: