Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 372
Michele Avatar asked Dec 05 '25 15:12

Michele


1 Answers

try

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

you seem to have only ipv6 enabled.

like image 55
User Avatar answered Dec 08 '25 09:12

User



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!