I remember a similar issue myself when accessing websites from behind a proxy. Since setting HTTP_PROXY environment variable and using wget works but the Python program does not, you may want to try using urllib2 instead of socket and specifically create a ProxyHandler object to complete the request successfully.
jtp
2010-09-20 15:17:39