Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gaierror: [Errno -2] Name or service not known

  def make_req(data, url, method='POST')  
    params = urllib.urlencode(data)
    headers = {"Content-type": "application/x-www-form-urlencoded",
               "Accept": "text/plain",
               }
    conn = httplib.HTTPSConnection(url)
    conn.request(method, url, params, headers)
    response = conn.getresponse()
    response_data = response.read()
    conn.close()

But it is throwing: in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno -2] Name or service not known

What is the reason ? What is this error?

like image 777
user12345 Avatar asked Mar 07 '11 16:03

user12345


People also ask

What is socket Gaierror Errno name or service not known?

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

What is a Gaierror?

It means that your given host name ' ' is invalid (gai stands for getaddrinfo() ).


1 Answers

You need to call request() with the URI relative to the server. If url is www.google.com/images?q=test you have to do:

conn = httplib.HTTPSConnection('www.google.com')
conn.request('GET', '/images?q=test')
like image 200
rubik Avatar answered Oct 20 '22 07:10

rubik