title: Python socket.error: [Errno 111] Connection refused on ubuntu 12.04
body: <p>I'm trying to use sockets with python, but I keep on getting this error message:</p>
  
  <pre><code>import socket
  &gt;&gt;&gt; s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
  &gt;&gt;&gt; s.connect(('localhost', 8000))
  Traceback (most recent call last):
    File "stdin", line 1, in module
    File "/usr/lib/python2.7/socket.py", line 224, in meth
      return getattr(self._sock,name)(*args)
  socket.error: [Errno 111] Connection refused
  </code></pre>
  
  <p>config in /etc/hosts is :</p>
  
  <pre><code>::1     ip6-localhost ip6-loopback
  fe00::0 ip6-localnet
  ff00::0 ip6-mcastprefix
  ff02::1 ip6-allnodes
  ff02::2 ip6-allrouters
  </code></pre>
  
  <p>System is ubuntu 12.04 , no firewall configured.
  Tried to change port number , but no luck; it works only with domains different from
   "localhost". Does someone knows why it happens?</p>