title: Python urllib2 cannot open localhost on alternate port (not 80)? Error 10013
body: <p>Here is my <strong>server.py</strong>:</p>
  
  <pre><code>import BaseHTTPServer
  import SocketServer
  
  class TestRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
      def do_GET(self):
          self.wfile.write("hello world at %s" % __file__)
  
  server = BaseHTTPServer.HTTPServer(('', 10000), TestRequestHandler)
  #server = SocketServer.ThreadingTCPServer(('', 8888), TestRequestHandler)
  server.serve_forever()
  </code></pre>
  
  <p>Here is my <strong>client.py</strong>:</p>
  
  <pre><code>import urllib2
  req = urllib2.Request('http://127.0.0.1:10000/')
  handle = urllib2.urlopen(req)
  content = handle.read()
  </code></pre>
  
  <p>Then I start server.py, it works.</p>
  
  <p>When I start client.py, I get this error on <strong>Windows 7, Python 2.6</strong>:</p>
  
  <pre><code>Traceback (most recent call last):
    File "D:\Dropbox\Forge\urllib-error\client.py", line 3, in &lt;module&gt;
      handle = urllib2.urlopen(req)
    File "C:\Python26\lib\urllib2.py", line 126, in urlopen
      return _opener.open(url, data, timeout)
    File "C:\Python26\lib\urllib2.py", line 391, in open
      response = self._open(req, data)
    File "C:\Python26\lib\urllib2.py", line 409, in _open
      '_open', req)
    File "C:\Python26\lib\urllib2.py", line 369, in _call_chain
      result = func(*args)
    File "C:\Python26\lib\urllib2.py", line 1161, in http_open
      return self.do_open(httplib.HTTPConnection, req)
    File "C:\Python26\lib\urllib2.py", line 1136, in do_open
      raise URLError(err)
  urllib2.URLError: &lt;urlopen error [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions&gt;
  </code></pre>
  
  <p>When I open <a href="http://127.0.0.1:10000/" rel="nofollow">http://127.0.0.1:10000/</a> from a browser, it works. It means server is fine.</p>
  
  <p>When I replace <a href="http://127.0.0.1:10000/" rel="nofollow">http://127.0.0.1:10000/</a> with <a href="http://127.0.0.1/" rel="nofollow">http://127.0.0.1/</a> or <a href="http://127.0.0.1:80/" rel="nofollow">http://127.0.0.1:80/</a> in client.py, everything works fine (this is another web server on port 80 - apache).</p>
  
  <p><strong>What do I do wrong?</strong></p>
  
  <p><strong>UPD:</strong> Same error when I use this <strong>client2.py</strong>:</p>
  
  <pre><code>import urllib2
  handle = urllib2.urlopen('http://127.0.0.1:10000/')
  content = handle.read()
  </code></pre>
  
  <p><strong>UPD:</strong> Problem solved. It was my firewall. When disabled, everything works. Stupid, stupid me. Thanks for reading :-)</p>