Read_nonblock' : end of file reached (EOFError)

hi. My environment is at the end.

I get an error like,

/Users/xxx/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:141:in
`read_nonblock’
: end of file reached (EOFError)

for a program

#-------------------
require ‘rubygems’
require ‘json’
require ‘net/http’
require ‘open-uri’

def search_google
api_key = ‘xxx’
base_url = ‘https://www.googleapis.com/customsearch/v1?key=
tail_url = ‘&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json’
url = base_url + api_key + tail_url
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
result = JSON.parse(data)
return result
end
search_google
#------------------

I have searched for the error but did not really understand the cause of
it.
Could anyone help me out?
Thanks in advance!

soichi

my environment:

ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
MacOSX SnowLeopard
installed gems

actionmailer (3.1.3)
actionpack (3.1.3)
activemodel (3.1.3)
activerecord (3.1.3)
activeresource (3.1.3)
activesupport (3.1.3)
addressable (2.2.6)
ansi (1.4.1)
arel (2.2.1)
builder (3.0.0)
bundler (1.0.21 ruby)
coffee-rails (3.1.1)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
commonjs (0.2.0)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.13)
faker (1.0.1)
heroku (2.17.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
json (1.6.4)
launchy (2.0.5)
less (2.0.8)
less-rails (2.1.2)
less-rails-bootstrap (1.4.2)
libv8 (3.3.10.4 x86_64-darwin-10)
mail (2.3.0)
mime-types (1.17.2)
multi_json (1.0.4)
net-http-persistent (2.3.3)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack-mount (0.8.3)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.1.3)
railties (3.1.3)
rake (0.9.2.2, 0.9.2)
rdoc (3.12)
rest-client (1.6.7)
rspec (2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
rspec-mocks (2.8.0)
rspec-rails (2.8.1)
ruby-json (1.1.2)
rubygems-update (1.8.15)
rubyzip (0.9.5)
sass (3.1.12)
sass-rails (3.1.5)
sprockets (2.0.3)
sqlite3 (1.3.5)
term-ansicolor (1.0.7)
therubyracer (0.9.9)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
turn (0.8.3)
tzinfo (0.3.31)
uglifier (1.2.1)

Try this:

def search_google
api_key = ‘xxx’
base_url = ‘https://www.googleapis.com/customsearch/v1?key=
tail_url = ‘&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json’
main_url = base_url + api_key + tail_url
url = URI.parse(URI.encode(main_url))
response = Net::HTTP.start(url.host, use_ssl: true, verify_mode:
OpenSSL::SSL::VERIFY_NONE) do |http|
http.get url.request_uri
end

case response
when Net::HTTPRedirection
# repeat the request using response[‘Location’]
when Net::HTTPSuccess
outputData = JSON.parse response.body
else
# response code isn’t a 200; raise an exception
pp response.error!
end
return outputData
end

i got the same error during devoloping an Siri-Proxy-Plugin…

i guess it’s a problem with https://… google-maps api with http://
works fine for me!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs