Hello everyone,
I’m new to ruby.I’m trying to write an application that would
synchronise with google calendar.Below is a script I’m trying to use for
authentication with google.When I try to run it I’m getting a bad file
descriptor error.I have also provided the error message just after the
script.Any help will be appriciated.Thank you in advance.
def authentication(email,passwd,service)
require ‘net/https’
http = Net::HTTP.new(‘www.google.com’, 443)
http.use_ssl = true
path = ‘/accounts/ClientLogin’
Now we are passing in our actual authentication data.
data = 'accountType=HOSTED_OR_GOOGLE&Email=email &Passwd=passwd
&service=service’
Set up a hash for the headers
headers = { ‘Content-Type’ => ‘application/x-www-form-urlencoded’}
Post the request and print out the response to retrieve our
authentication token
resp, data = http.post(path, data, headers)
Strip out our actual token (Auth) and store it
cl_string = data[/Auth=(.*)/, 1]
Build our headers hash and add the authorization token
headers[“Authorization”] = “GoogleLogin auth=#{cl_string}”
end
#After calling this function like this:
authentication(“[email protected]”,“passwd”,“cl”)
#I get the follow error message:
Errno::EBADF: Bad file descriptor
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in write' from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in
warn’
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in connect' from C:/Ruby/lib/ruby/1.8/net/http.rb:553:in
do_start’
from C:/Ruby/lib/ruby/1.8/net/http.rb:542:in start' from C:/Ruby/lib/ruby/1.8/net/http.rb:1035:in
request’
from C:/Ruby/lib/ruby/1.8/net/http.rb:845:in post' from (irb):15:in
authentication’
from (irb):23
from :0
irb(main):024:0>
Errno::EBADF: Bad file descriptor
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in write' from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in
warn’
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in connect' from C:/Ruby/lib/ruby/1.8/net/http.rb:553:in
do_start’
from C:/Ruby/lib/ruby/1.8/net/http.rb:542:in start' from C:/Ruby/lib/ruby/1.8/net/http.rb:1035:in
request’
from C:/Ruby/lib/ruby/1.8/net/http.rb:845:in post' from (irb):15:in
authentication’
from (irb):23
from :0
irb(main):024:0>
It may mean that google has summarily hung up on you.
-=r
Roger P. wrote:
Errno::EBADF: Bad file descriptor
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in write' from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in
warn’
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in connect' from C:/Ruby/lib/ruby/1.8/net/http.rb:553:in
do_start’
from C:/Ruby/lib/ruby/1.8/net/http.rb:542:in start' from C:/Ruby/lib/ruby/1.8/net/http.rb:1035:in
request’
from C:/Ruby/lib/ruby/1.8/net/http.rb:845:in post' from (irb):15:in
authentication’
from (irb):23
from :0
irb(main):024:0>
It may mean that google has summarily hung up on you.
-=r
Thank you Roger.Any suggestions on how I can fix this problem?Do I have
to changing some parameters or something in those lines?
It may mean that google has summarily hung up on you.
-=r
Thank you Roger.Any suggestions on how I can fix this problem?Do I have
to changing some parameters or something in those lines?
very carefully check the parameters to make sure they’re right is the
only thing I can imagine.
On 12.04.2009 04:58, Roger P. wrote:
from :0
irb(main):024:0>
It may mean that google has summarily hung up on you.
I believe you would see a different error. EBADF occurs, if the file
descriptor (i.e. the numeric value) is invalid. You can provoke it by
doing something like this
ruby -e ‘File.open(10, “w”) {|f| f.puts “test”}’
Whereas it does not happen if you do
ruby -e ‘File.open(1, “w”) {|f| f.puts “test”}’
One way to create this is to open a file, remember the number returned
from #fileno, close the file and then open another file with the
remembered number (file descriptor).
Kind regards
robert