urllib2 fails when URL has a port number appended
Question: The code below:

    
    
    import urllib2
    file = urllib2.urlopen("http://foo.bar.com:82")
    

works just fine on my mac (OS X 10.8.4 running Python 2.7.1. It opens the URL
and I can parse the file with no problems.

When I try the EXACT same code (these two lines) in GoDaddy Python 2.7.3 (or
2.4) I receive an error:

    
    
    urllib2.URLError: <urlopen error (111, 'Connection refused')
    

The problem has something to do with the port :82 that is an essential part of
the address. I have tried using a forwarding address with masking, etc., and
nothing works.

Any idea why it would work in one environment and not in the other (ostensibly
similar) environment? Any ideas how to get around this? I also tried Mechanize
to no avail. Previous posts have suggested focusing on
urllib2.HTTPBasicAuthHandler, but it works fine on my OS X environment without
anything special.

Ideas are welcome.


Answer: `Connection refused` means that your operating system tried to contact the
remote host, but got a "closed port" message.

Most likely, this is because of a firewall between GoDaddy and `foo.bar.com`.
Most likely, `foo.bar.com` is only reachable from your computer or your local
network, but it also could be GoDaddy preventing access to strange ports.

