Getaddrinfo: Nodename Nor Servname Provided, or Not Known

getaddrinfo: nodename nor servname provided, or not known

The error occurs when the DNS resolution fails. Check if you can wget (or curl) the api url from the command line. Changing the DNS server and testing it might help.

How to handle SocketError - getaddrinfo: nodename nor servname provided, or not known [ruby]

Since you are using version 2 of RestClient, The recommended way is to add rescue RestClient::ExceptionWithResponse => e #do something with e.response before end in your method.

You can see the full list of all exceptions that RestClient can raise here: https://github.com/rest-client/rest-client#exceptions-see-httpwwww3orgprotocolsrfc2616rfc2616-sec10html .

I would suggest to try and catch them all :)

Net::HTTP SocketError: getaddrinfo: nodename nor servname provided, or not known

You have to pass an URI object to the get_response method so that it has scheme and host etc. info in it:

URI('http://www.apple.com').host
# => "www.apple.com"
URI('http://www.apple.com').scheme
# => "http"

So, to solve your problem, do it this way:

Net::HTTP.get_response(URI("http://www.apple.com"))
# => #<Net::HTTPOK 200 OK readbody=true>

To get the response body, do this:

Net::HTTP.get_response(URI("http://www.apple.com")).body

See the get_response documentation for more details.

SocketError: getaddrinfo: nodename nor servname provided when trying to access US Census Tigerline Shapefiles FTP server

The initialize method of the Net::FTP class expects a hostname (or IP) as its argument, not an FTP URL. Following the examples from the documentation, this should work instead:

ftp = Net::FTP.new('ftp2.census.gov')
ftp.login
files = ftp.list('/geo/tiger/TIGER2010/BG/2010')
# => file listing of the directory

Please see the documentation for the Net::FTP class for details on how to access remote files and directories.

Getting `initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError) when saying smtp.start

I'll answer my question here so it doesn't appear as unanswered since I found out what caused this error.

So, just after posting this question I realized that I had accidentally blocked access to smtp.google.com in Hands Off! My bad. So, this issue is solved now and everything works like it should.



Related Topics



Leave a reply



Submit