Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google AppEngine Urlfetch instead of urllib2

What is the difference between Google's urlfetch over the python lib urllib2 ?

When I came upon Google's urlfetch I thought maybe there were security reasons. Perhaps Google is safer in terms of malicous urls or something?

Is there any reason why I should choose Google's urlfetch over urllib2?

like image 769
mrmclovin Avatar asked Dec 21 '22 14:12

mrmclovin


2 Answers

Note that in GAE urllib, urllib2 and httplib are just wrappers around UrlFetch (See Fetching urls in Python).

One difference of the urlfetch module is that provides you with an interface for making Asynchronous requests.

like image 97
Sebastian Kreft Avatar answered Jan 06 '23 05:01

Sebastian Kreft


I don't work for Google, so this is just a guess from various GAE posts I've read. App Engine instances don't face the internet directly, but are buried behind layers of Google infrastructure. When a browser makes an HTTP request, it doesn't go straight to your instance, but rather it hits a Google edge server which eventually routes the request to a GAE instance.

Likewise when making an HTTP request out, your instance doesn't just open a socket (which urllib2 will normally do), but rather it sends the HTTP request to some other Google edge server which goes makes that HTTP request. Using urllib2 on GAE will use a GAE specific version which runs on top of urlfetch.

like image 45
dragonx Avatar answered Jan 06 '23 06:01

dragonx