title: how can I get the total bytes sent and received using python 2.7?
body: <p>Is there a way to calculate the total sent and total received bytes in python 2.7 application using urllib2 library? I cannot see any method or variable holding this value when I look at the methods/variables of Request object and response which can be seen below. I checked the urllib2 library however I could not find what I wanted.</p>
  
  <p>Here is my simple example;</p>
  
  <pre><code>#!/usr/bin/python2.7
  # encoding: utf-8
  from __future__ import print_function
  import urllib2
  
  req = urllib2.Request('http://example.com')
  print(dir(req))
  response = urllib2.urlopen(req)
  print(dir(response))
  the_page = response.read()
  print("Length:" + str(len(the_page)))
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>['_Request__fragment', '_Request__original', '__doc__', '__getattr__', '__init__', '__module__', '_tunnel_host', 'add_data', 'add_header', 'add_unredirected_header', 'data', 'get_data', 'get_full_url', 'get_header', 'get_host', 'get_method', 'get_origin_req_host', 'get_selector', 'get_type', 'has_data', 'has_header', 'has_proxy', 'header_items', 'headers', 'host', 'is_unverifiable', 'origin_req_host', 'port', 'set_proxy', 'type', 'unredirected_hdrs', 'unverifiable']
  ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close', 'code', 'fileno', 'fp', 'getcode', 'geturl', 'headers', 'info', 'msg', 'next', 'read', 'readline', 'readlines', 'url']
  Length:1270
  </code></pre>
  
  <p>Web server may send the content compressed, of course simple <code>len(the_page)</code> is not enough for total received bytes. My constraint is not to use any other library other than urllib2, urllib, httplib under python2.7 to achieve this.</p>
  
  <p>Any help will be appreciated to find the total sent bytes and total received bytes.</p>