Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOCKET ERROR: [Errno 111] Connection refused

I am using simple python lib for the SMTP But i am getting this error:

import smtplib smtpObj = smtplib.SMTP('localhost')  Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/lib/python2.7/smtplib.py", line 249, in __init__     (code, msg) = self.connect(host, port)   File "/usr/lib/python2.7/smtplib.py", line 309, in connect     self.sock = self._get_socket(host, port, self.timeout)   File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket     return socket.create_connection((port, host), timeout)   File "/usr/lib/python2.7/socket.py", line 571, in create_connection     raise err socket.error: [Errno 111] Connection refused 

Using python-2.7

like image 603
Nishant Kashyap Avatar asked Dec 03 '13 10:12

Nishant Kashyap


People also ask

What is ERROR 111 Connection refused?

What's Causing This Error. The SMTP 111 error occurs when an issue is present while connecting with the remote SMTP server. For example, you would run into this error due to invalid sender domains or firewall issues.

How to solve Connection refused ERROR in python?

check from the server, if you're accepting the connections to the server: again based on your OS, but telnet LISTENING_IP LISTENING_PORT should do the job. check if you can access the port of the server from the client, but not using the code: just us the telnet (or appropriate command for your OS) from the client.


2 Answers

Start a simple SMTP server with Python like so:

python -m smtpd -n -c DebuggingServer localhost:1025 

or you can also try gmail smtp setting

server = smtplib.SMTP(host='smtp.gmail.com', port=587) 
like image 115
Yogesh dwivedi Geitpl Avatar answered Sep 21 '22 08:09

Yogesh dwivedi Geitpl


if you:

python -m smtpd -n -c DebuggingServer localhost:1025 

as suggested by Allen Thomas, then make sure you init:

server = smtplib.SMTP(host='localhost', port=1025) 

with matching port number, here: 1025.

like image 31
andilabs Avatar answered Sep 24 '22 08:09

andilabs