Michele
Michele

Reputation: 41

Python socket.error: [Errno 111] Connection refused on ubuntu 12.04

I'm trying to use sockets with python, but I keep on getting this error message:

import socket
>>> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
>>> 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

config in /etc/hosts is :

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

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?

Upvotes: 3

Views: 8701

Answers (1)

User
User

Reputation: 14893

try

s = socket.socket( socket.AF_INET6, socket.SOCK_STREAM )
s.connect(('::1', 8000))

you seem to have only ipv6 enabled.

Upvotes: 2

Related Questions