Using Google AppEngine Urlfetch instead of urllib2

What is the difference between google urlfetch over python lib urllib2 ?

When I came across Google urlfetch , I thought there might have been security concerns. Perhaps Google is more secure in terms of malicious URLs or something else?

Is there a reason why I should choose google urlfetch through urllib2 ?

+4
source share
4 answers

I do not work for Google, so this is just an assumption from the various GAE posts I read. App Engine instances do not access the Internet directly, but hide behind layers of Google’s infrastructure. When the browser makes an HTTP request, it does not go directly to your instance, but rather gets to the Google Edge server, which ultimately routes the request to the GAE instance.

Similarly, when you send an HTTP request, your instance does not just open the socket (usually urllib2), but rather sends an HTTP request to some other Google Edge server that sends this HTTP request. Using urllib2 in GAE will use a specific version of GAE that runs on top of urlfetch.

+5
source

Note that in GAE, urllib, urllib2, and httplib are just wrappers around UrlFetch (see Getting URLs in Python ).

One difference with the urlfetch module is that you provide an interface for creating asynchronous requests .

+8
source

No problem using standard libraries in App Engine. Url Fetch Api is just a service to make an HTTP request more "easy" than urlib2. This is more understandable for beginners in Python, and you can easily use a request without blocking, for example.

I suggest you read more information here: https://developers.google.com/appengine/docs/python/urlfetch/overview

If Google has discovered some security issue in the standard Python libraries. I assume he will send a fix;)

0
source

The difference is this: urlfetch has only a functional interface, and urllib and httplib have an OO interface. The OO interface can be very useful. I saw a good example in the oauth2 client library, where a request instance is passed to the client library to check if the token is valid and allowed.

-2
source

Source: https://habr.com/ru/post/1440751/


All Articles