Using Google AppEngine Urlfetch instead of urllib2

google-app-engine, security, urlfetch, urllib2

Solution

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.

Problem

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`?

Original source