Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting a "connection reset by peer" error when hitting Google Contacts API

I'm trying to pull Google Contacts into a Rails application using the Google Contacts API. I've completed the Oauth2 handshake, and am now requesting the protected resource with my access token. Here is the code:

uri = URI('https://www.google.com/m8/feeds/contacts/default/full')
params = { :client_id => APP_CONFIG[:google_api_client_id],
           :access_token => auth.access_token,
           "max-results".to_sym => max_results
         }

uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
like image 523
user276712 Avatar asked Feb 17 '12 23:02

user276712


People also ask

What does connection reset by peer error mean?

This error is generated when the OS receives notification of TCP Reset (RST) from the remote peer. Connection reset by peer means the TCP stream was abnormally closed from the other end. A TCP RST was received and the connection is now closed.

How do I Fix Google Chrome errors like “err connection reset”?

Turn the toggle for Real-time protection to the Off position. Your firewall blocks suspicious network connections on your computer. It might be that your Chrome connections are considered suspicious by your firewall, and so Chrome is disabled from making any connection requests. This can cause Chrome to display errors like "Err connection reset."

What is an err_connection_reset error?

Connection reset errors appear when you visit a website, and the browser fails to establish a connection. When that happens, the connection is “reset,” which means the server cannot transmit data to your browser. Here’s what the “ERR_CONNECTION_RESET” message looks like in Chrome:

What is TCP reset by peer?

This error is generated when the OS receives notification of TCP Reset (RST) from the remote peer. Connection reset by peer means the TCP stream was abnormally closed from the other end.


1 Answers

You're requesting an HTTPS resource, so your GET request needs to use SSL encryption.

http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-use_ssl-3F

So your last line should look like:

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE # You should use VERIFY_PEER in production
  request = Net::HTTP::Get.new(uri.request_uri)
  res = http.request(request)
like image 123
bdon Avatar answered Oct 14 '22 00:10

bdon