. Advertisement .
..3..
. Advertisement .
..4..
I encountered the following problem in completing my work:
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 307, in _get_socket
self.source_address)
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\socket.py", line 705, in create_connection
for res in getaddrinfo(host, port, 1, SOCK_STREAM):
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 10047] getaddrinfo failed
Below is the code I ran:
SERVER_EMAIL = '[email protected]'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'password_here'
EMAIL_HOST_USER = SERVER_EMAIL
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
class ContactView(generic.TemplateView):
template_name = "contact.html"
def post(self,request,*args,**kwargs):
send_mail(
'Subject here',
'Here is the message.',
EMAIL_HOST_USER,
['[email protected]'],
fail_silently=False,
)
What’s causing it, and how can it be resolved in the “socket.gaierror: [errno -2] name or service not known“ in the python?
The cause:
The problem
socket.gaierror: [Errno -2] Name or service not known
signifies that the domain’s name resolution is failing (api.github.com).Name resolution can go wrong for a variety of reasons. Because you’ve turned off the internet, the reason is identity (Name or service not known).
Solution:
Gai
(GetAddressInfo) is a component ofglibc
that is used to do name resolves (and usingsocket
which can visualize). You can also change the settings in/etc/gai.conf
.Your problem is not popular and not easy to find the correct answer, however I will provide you the relevant expertise to get it in. I hope it help Socket programming is the process of connecting two nodes within the network to talk to one another. One socket(node) is listening on the port of a specific IP and another socket connects to the other socket to establish an internet connection. The server creates the listener socket, while the client is reaching out at the server. They form the core for the web browser. In simple words, there’s two components: a client and a server. Socket programming begins by downloading the socket library, and creating a basic socket.
Also, here is sample for your reference