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.
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.
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 :)
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.
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.
Related Topics
How to Give a Sub-Module the Same Name as a Top-Level Class
Ruby Converting String Encoding from Iso-8859-1 to Utf-8 Not Working
Does Ruby 1.9.2 Have an Is_A? Function
Change Default Date Format in Ruby on Rails
Undefined Local Variable Based on Syntax in Ruby
How to Format a Date to Mm/Dd/Yyyy in Ruby
Can't Get to Work Cocoapods and Yosemite
How to Solve the 'Object Doesn't Support #Inspect' Error
How to Render a PDF in the Browser That Is Retrieve via Rails Controller
Async Requests Using Sinatra Streaming API
Activerecord Connection Warning. (Database Connections Will Not Be Closed Automatically)
Simplify Multiple Nil Checking in Rails
Why Does Ruby Builder::Xmlmarkup Add Inspect Tag to Xml
Is There a Difference Between :: and . When Calling Class Methods in Ruby
Why Does Rails 4.2 + Responders Keeps Telling Me to Add Responders to the Gemfile