Forum: Ruby Bad file descriptor error using Net::HTTP

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D0d6cc495dba62f1302d7a88561d14d8?d=identicon&s=25 unknown (Guest)
on 2007-06-28 16:21
(Received via mailing list)
I am trying to access a .net page via my ruby app and pass it a couple
parameters. Every thing I have tried has resulted in this Bad file
descriptor, I am wondering if it is something wrong with my
configuration, not the code. Here is the code that is causing
problems:

Net::HTTP.version_1_2
    Net::HTTP.start('www.url.com', 80) {
     |http|
     response =
        http.post('/DoSomething.aspx',
'id=#{params[:id]}&path=#{params[:imagerecord]}',
                  { 'Content-Type' => 'application/x-www-form-
urlencoded' })
     puts response.body()
   }

Here is the error I get:

Errno::EBADF (Bad file descriptor - connect(2)):
    c:/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize'
    c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
    c:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
    c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
    c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
    c:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
    c:/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
    c:/ruby/lib/ruby/1.8/net/http.rb:440:in `start'

I am on Windows 2003 serer with Ruby 1.8.4 and Mongrel. Any help would
be greatly appreciated.
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2007-06-28 16:58
(Received via mailing list)
On Jun 28, 8:20 am, brian.wil.gre...@gmail.com wrote:
>         http.post('/DoSomething.aspx',
>     c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
>     c:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
>     c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
>     c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
>     c:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
>     c:/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
>     c:/ruby/lib/ruby/1.8/net/http.rb:440:in `start'
>
> I am on Windows 2003 serer with Ruby 1.8.4 and Mongrel. Any help would
> be greatly appreciated.

Line 560 of net/http.rb is this:

s = timeout(@open_timeout) { TCPSocket.open(conn_address(),
conn_port()) }

What happens when you run this standalone snippet?

require 'socket'
require 'timeout'

s = Timeout.timeout(5){
   TCPSocket.open(url, 80)
}

p s

s.close

Regards,

Dan
D0d6cc495dba62f1302d7a88561d14d8?d=identicon&s=25 unknown (Guest)
on 2007-06-28 17:21
(Received via mailing list)
On Jun 28, 10:57 am, Daniel Berger <djber...@gmail.com> wrote:
> > Net::HTTP.version_1_2
> > Here is the error I get:
>
> require 'socket'
>
> Regards,
>
> Dan


Dan,

Thanks. Here is the error I get when executing the above code:

Timeout::Error (execution expired):
c:/ruby/lib/ruby/1.8/timeout.rb:54:in `open'
c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'

I know it's a valid URL. The page I am trying to access is sitting on
the same box as my rails app.
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2007-06-28 19:08
(Received via mailing list)
On Jun 28, 9:20 am, brian.wil.gre...@gmail.com wrote:
> On Jun 28, 10:57 am, Daniel Berger <djber...@gmail.com> wrote:

<snip>

> > require 'socket'
>
> c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
>
> I know it's a valid URL. The page I am trying to access is sitting on
> the same box as my rails app.

That's peculiar. Firewall or proxy issue perhaps? Maybe you need
rubysspi?

http://rubyforge.org/projects/rubysspi/

Otherwise, I'm at a loss.

Regards,

Dan
This topic is locked and can not be replied to.