Bad file descriptor error

Discussion in 'Ruby' started by Mwenge Mulenga, Apr 11, 2009.

  1. 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("","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>
    --
    Posted via http://www.ruby-forum.com/.
    Mwenge Mulenga, Apr 11, 2009
    #1
    1. Advertising

  2. Mwenge Mulenga

    Roger Pack Guest


    > 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
    --
    Posted via http://www.ruby-forum.com/.
    Roger Pack, Apr 12, 2009
    #2
    1. Advertising

  3. Roger Pack 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?
    --
    Posted via http://www.ruby-forum.com/.
    Mwenge Mulenga, Apr 12, 2009
    #3
  4. Mwenge Mulenga

    Roger Pack Guest


    >> 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.

    --
    Posted via http://www.ruby-forum.com/.
    Roger Pack, Apr 12, 2009
    #4
  5. Roger Pack wrote:
    >
    >>> 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.


    I definately will.
    --
    Posted via http://www.ruby-forum.com/.
    Mwenge Mulenga, Apr 12, 2009
    #5
  6. On 12.04.2009 04:58, Roger Pack 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.


    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
    Robert Klemme, Apr 12, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    4
    Views:
    1,040
    David Bolen
    Jul 7, 2003
  2. drs
    Replies:
    0
    Views:
    363
  3. Replies:
    9
    Views:
    701
    Abhijit Soman
    Jan 6, 2005
  4. Vishnu
    Replies:
    0
    Views:
    499
    Vishnu
    Jan 6, 2005
  5. lynology

    Bad File Descriptor Error on strcat/strcpy

    lynology, Aug 18, 2004, in forum: C Programming
    Replies:
    4
    Views:
    486
    Chris Torek
    Aug 18, 2004
Loading...

Share This Page