Urllib2 urlopen and read - difference

koranthala koranthala at gmail.com
Thu Apr 15 14:25:55 EDT 2010

   Suppose I am doing the following:
req = urllib2.urlopen('http://www.python.org')
data = req.read()

   When is the actual data received? is it done by the first line? or
is it done only when req.read() is used?
  My understanding is that when urlopen is done itself, we would have
received all the data, and req.read() just reads it from the file
  But, when I read the source code of pylot, it mentioned the
            resp = opener.open(request)  # this sends the HTTP request
and returns as soon as it is done connecting and sending
            connect_end_time = self.default_timer()
            content = resp.read()
            req_end_time = self.default_timer()

Here, it seems to suggest that the data is received only after you do
resp.read(), which made me all confused.

If someone could help me out, it would be much helpful.

More information about the Python-list mailing list