1

Right now I am currently running into this error message while making a simple GET request in ruby:

#<SocketError: Failed to open TCP connection to api.github.com:443 (getaddrinfo: nodename nor servname provided, or not known)>

This is my ruby code:

require 'uri'
require 'net/http'

class RequestDouble
  def initialize(endpoint)
    @endpoint = endpoint
  end


  def send_get_request
    url = URI(endpoint)
    https = Net::HTTP.new(url.host, url.port)
    https.use_ssl = true
    request = Net::HTTP::Get.new(url)
    request['Content-Type'] = 'application/json'
    response = https.request(request)
    JSON.parse(response.read_body)
  rescue StandardError => e
    { 'status' => 500, 'detail' => 'Something went wrong' }
  end

  private


  attr_accessor :endpoint

end

And this is the execution of the request:

github_request = RequestDouble.new('https://api.github.com/repos/robskrob/personal-site')
github_request.send_get_request

Does anyone see why I'm getting the above SocketError message? Does anyone know how I can successfully make the GET request in ruby? This request https://api.github.com/repos/robskrob/personal-site works just fine in postman and in my browser.

robskrob
  • 2,720
  • 4
  • 31
  • 58

1 Answers1

1

Ok so I am not 100 percent certain as to why this worked but all I had to was turn my computer off and on. This SO post navigated me to the decision. curl was working for me in making the request in my shell so there had to be something badly cached on the ruby side of things as it related to the network.

robskrob
  • 2,720
  • 4
  • 31
  • 58