Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Bad file descriptor error using Net::HTTP

Reply
Thread Tools

Bad file descriptor error using Net::HTTP

 
 
brian.wil.greene@gmail.com
Guest
Posts: n/a
 
      06-28-2007
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.

 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      06-28-2007


On Jun 28, 8:20 am, (E-Mail Removed) wrote:
> 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.


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


 
Reply With Quote
 
 
 
 
brian.wil.greene@gmail.com
Guest
Posts: n/a
 
      06-28-2007
On Jun 28, 10:57 am, Daniel Berger <(E-Mail Removed)> wrote:
> On Jun 28, 8:20 am, (E-Mail Removed) wrote:
>
>
>
> > 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.

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



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.

 
Reply With Quote
 
Daniel Berger
Guest
Posts: n/a
 
      06-28-2007
On Jun 28, 9:20 am, (E-Mail Removed) wrote:
> On Jun 28, 10:57 am, Daniel Berger <(E-Mail Removed)> wrote:


<snip>

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

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


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


 
Reply With Quote
 
plamb
Guest
Posts: n/a
 
      07-02-2007
On Jun 28, 9:27 am, Daniel Berger <(E-Mail Removed)> wrote:
> On Jun 28, 9:20 am, (E-Mail Removed) wrote:
>
> > On Jun 28, 10:57 am, Daniel Berger <(E-Mail Removed)> wrote:

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

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

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


I ran into the same error when I attempted to get a page with an
improperly formatted URL. I tried to get 'www.google.com', which
failed with the same error you encountered. I realized I didn't
include 'http', and when I tried again with 'http://www.google.com' it
worked as anticipated.

---
Paul

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
file.readlines() - gives me error (bad file descriptor) wordsender@gmail.com Python 9 01-06-2005 02:02 PM
RE: file.readlines() - gives me error (bad file descriptor) Vishnu Python 0 01-06-2005 06:33 AM
Bad File Descriptor Error on strcat/strcpy lynology C Programming 4 08-18-2004 04:06 PM
dcom & Bad File Descriptor error drs Python 0 07-09-2003 07:51 AM
Threading issue: [Error 9]: bad file descriptor Kevin Python 4 07-07-2003 10:19 PM



Advertisments