modified to use raw urllib2 functions instead of requests library