I trying to get validate_email package (https://pypi.python.org/pypi/validate_email) to verify an email for me on a Windows 7/Python 2.7 device. The following works:
>>> validate_email('example#example.com')
True
>>> validate_email('example#example.com',check_mx=True)
True
>>> validate_email('example#example.com',verify=True)
True
But when I try a commercial email server example to check if the host has SMPT Server and/or the email really exists, it fails as follows:
>>> validate_email('example#gmail.com')
True
>>> validate_email('example#gmail.com',check_mx=True)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\validate_email.py", line 104, in validate_email
smtp.connect(mx[1])
File "C:\Python27\lib\smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
>>> validate_email('example#gmail.com',verify=True)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\validate_email.py", line 104, in validate_email
smtp.connect(mx[1])
File "C:\Python27\lib\smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
It appears that I'm trying to access a port that I don't have permission to, but I don't know how to change to a port that would work and has the correct permissions.
Any suggestions?
It looks like this could be a problem with Windows Firewall blocking access to certain ports.
https://stackoverflow.com/a/15628078/1308566
Related
All lines starting from line all return an error Errno 10060 or an error Errno 10061:
import smtplib
server = smtplib.SMTP('smtp.gmail.com:465')
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer = smtplib.SMTP("smtp.gmail.com", 465)
mailServer = smtplib.SMTP("smtp.mail.ru", 25)
mailServer = smtplib.SMTP("smtp.mail.ru", 2525)
Could you help? I must be missing something trivial... Error messages in full:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Use smtplib.SMTP_SSL() for a TLS connection.
There is nothing wrong with all commands below; my issue is indeed caused by IP restrictions. Thanks for all your answers.
Or Use server = smtplib.SMTP('smtp.gmail.com:25') for normal connection
and if you want tls from port 25, simply add
server.starttls()
after the first line.
ps: since port 25 is default, the following is equivalent:
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()
I'm following this guide here https://github.com/flaree/Flare-Cogs/tree/master/dankmemer. I got to the import rethinkdb part but I get this error when running the r.connect('localhost', 28015).repl()
command. Been searching yesterday for a fix but couldn't find one.
r.connect('localhost', 28015).repl()
Traceback (most recent call last):
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 349, in __init__
self._socket = socket.create_connection((self.host, self.port), timeout)
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/venv/lib/python3.8/site-packages/rethinkdb/__init__.py", line 93, in connect
return self.make_connection(self.connection_type, *args, **kwargs)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 830, in make_connection
return conn.reconnect(timeout=timeout)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 696, in reconnect
return self._instance.connect(timeout)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 538, in connect
self._socket = SocketWrapper(self, timeout)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 437, in __init__
raise ReqlDriverError(
rethinkdb.errors.ReqlDriverError: Could not connect to localhost:28015. Error: [Errno 111] Connection refused```
You need to run rethinkdb first.
Enter your venv, and run tmux. Then run rethinkdb inside your tmux shell. This starts the rethinkdb server, and keeps it running. Close the SSH session, and open another one. Try running your code again.
I am new to Python and trying to run attached code.
import urllib
url = 'https://www.google.com/'
print(url)
sock = urllib.urlopen(url)
But I get an error below:
>>> runfile('C:/Users/myname/Documents/Python Scripts/ex00.py', wdir=r'C:/Users/myname/Documents/Python Scripts')
https://www.google.com/
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Users/myname/Documents/Python Scripts/ex00.py", line 5, in <module>
sock = urllib.urlopen(url)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\urllib.py", line 437, in open_https
h.endheaders(data)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\httplib.py", line 969, in endheaders
self._send_output(message_body)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\httplib.py", line 829, in _send_output
self.send(msg)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\httplib.py", line 791, in send
self.connect()
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\httplib.py", line 1172, in connect
self.timeout, self.source_address)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\socket.py", line 571, in create_connection
raise err
IOError: [Errno socket error] [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Earlier I thought that it is may be because I am running the script from my office and VPN is causing issues. So I ran it from my home internet connection but no resolution :(
All lines starting from line all return an error Errno 10060 or an error Errno 10061:
import smtplib
server = smtplib.SMTP('smtp.gmail.com:465')
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer = smtplib.SMTP("smtp.gmail.com", 465)
mailServer = smtplib.SMTP("smtp.mail.ru", 25)
mailServer = smtplib.SMTP("smtp.mail.ru", 2525)
Could you help? I must be missing something trivial... Error messages in full:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Use smtplib.SMTP_SSL() for a TLS connection.
There is nothing wrong with all commands below; my issue is indeed caused by IP restrictions. Thanks for all your answers.
Or Use server = smtplib.SMTP('smtp.gmail.com:25') for normal connection
and if you want tls from port 25, simply add
server.starttls()
after the first line.
ps: since port 25 is default, the following is equivalent:
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()
I'm running a Mac OS X and used postfix to enable localhost.
This is the error message I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 61] Connection refused
Use netstat to verify that a SMTP server is bound to port 25 of an appropriate interface in the first place.
Check the postfix log file, which might be at /var/log/mail or something similar, depending on how you installed postfix.