Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Can I fix the “socket.gaierror: [errno -2] name or service not known” or not?
Next
Answered
Liam Cochet
  • 8
Liam Cochet
Asked: May 17, 20222022-05-17T13:01:53+00:00 2022-05-17T13:01:53+00:00In: python

Can I fix the “socket.gaierror: [errno -2] name or service not known” or not?

  • 8

. 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?

django
  • 2 2 Answers
  • 1k Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-06T09:11:34+00:00Added an answer on June 6, 2022 at 9:11 am

    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 of glibc that is used to do name resolves (and using socket which can visualize). You can also change the settings in /etc/gai.conf.

    • 16
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. trompdashawn
    2022-05-25T06:18:19+00:00Added an answer on May 25, 2022 at 6:18 am

    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.

    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    Also, here is sample for your reference

    # An example script to connect to Google using socket
    # programming in Python
    import socket # for socket
    import sys
    
    try:
       s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       print ("Socket successfully created")
    except socket.error as err:
       print ("socket creation failed with error %s" %(err))
    # default port for socket port = 80 try: host_ip = socket.gethostbyname('www.google.com') except socket.gaierror: # this means could not resolve the host print ("there was an error resolving the host") sys.exit() # connecting to the server s.connect((host_ip, port)) print ("the socket has successfully connected to google")
    • 6
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.