Google Groups Home
Help | Sign in
HTTP.get problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Ken Kaplan  
View profile
 More options Jul 8 2005, 6:31 pm
Newsgroups: comp.lang.ruby
From: "Ken Kaplan" <kkap...@isher.com>
Date: Sat, 9 Jul 2005 07:31:32 +0900
Local: Fri, Jul 8 2005 6:31 pm
Subject: HTTP.get problem

I'm new to ruby, and I've run into a problem while reading 'Programming
Ruby'. The 'Basic Input and Output' chapter has this example (I've added the
'puts' statements):

require 'net/http'

   h = Net::HTTP.new('www.pragmaticprogrammer.com', 80)
puts 'before get'
   resp, data = h.get('/index.html', nil)
puts 'after get'
   if resp.message == "OK"
     data.scan(/<img src="(.*?)"/) { |x| puts x }
   end

The above code hangs (but terminates ok with ctl-break) after 'before get',
and never reaches 'after get'. There is something up with my machine,
because a coworker can run this fine on his.

Things I've tried :

1.             'ping www.pragmaticprogrammer.com
<http://www.pragmaticprogrammer.com/> ' from the same command prompt. This
works fine.
2.             try with other web sites. No difference
3.             uninstalled, registry cleanup (CCleaner), reboot and
reinstalled ruby versions 182-14 and 182-15. No difference.
4.             'gem list ---remote' output gets to 'Updating Gem source
index for::/gems.rubyforge.org' and then hangs just like the above code.
5.             Turned off firewall (ZoneAlarm) and anti-spyware (Microsoft).
No difference.
6.             Added exception handling. No difference.

Any suggestions?

Ken

ruby --version

ruby 1.8.2 (2004-12-25) [i386-mswin32]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gene Tani  
View profile
 More options Jul 9 2005, 1:51 am
Newsgroups: comp.lang.ruby
From: "Gene Tani" <gene.t...@gmail.com>
Date: 8 Jul 2005 22:51:01 -0700
Local: Sat, Jul 9 2005 1:51 am
Subject: Re: HTTP.get problem
what does open-uri do?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gene Tani  
View profile
 More options Jul 9 2005, 1:58 am
Newsgroups: comp.lang.ruby
From: "Gene Tani" <gene.t...@gmail.com>
Date: 8 Jul 2005 22:58:19 -0700
Local: Sat, Jul 9 2005 1:58 am
Subject: Re: HTTP.get problem
I think i was getting same thing, found the post:

http://groups-beta.google.com/group/comp.lang.ruby/browse_frm/thread/...

anoth theory: my ISP's throttling/filtering me back.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
daz  
View profile
 More options Jul 9 2005, 3:37 am
Newsgroups: comp.lang.ruby
From: "daz" <do...@d10.karoo.co.uk>
Date: Sat, 9 Jul 2005 08:37:23 +0100
Local: Sat, Jul 9 2005 3:37 am
Subject: Re: HTTP.get problem

Ken Kaplan wrote:

> Things I've tried :     [...]

> 5.  Turned off firewall (ZoneAlarm) - No difference.

I would have suspected that, first.
You *closed* ZA ?  (Not recommended ever, while online, BTW)

You should have an entry under programs for:
  Ruby interpreter         1,8,2,0
For this script you need:  Allow connect (Internet)
  I have "?Ask" Server (Local/Internet)

OK, you say it's not a firewall problem.

> Any suggestions?

> ruby 1.8.2 (2004-12-25) [i386-mswin32]

Here's a trace log of what should happen on your
version of Ruby.

http://www.d10.karoo.net/ruby/pptrace.txt

Try running this modified version of your script and
report which trace line number you reach.
If the last 10-20 lines of your trace vary from mine,
post them here and someone who understands this stuff
may be able to help.

#--------------------------------------------------------
$tr_line = 1
$tr_func = lambda do | ev, fi, li, ty, bi, cl |
  printf("%04d %14s:%4d %26s  %-8s  %s\n",
          $tr_line, File.basename(fi), li, ty, ev, cl)
  $tr_line += 1
end

STDOUT.sync=true
require 'net/http'

h = Net::HTTP.new('www.pragmaticprogrammer.com', 80)

  set_trace_func($tr_func)
resp, data = h.get('/index.html', nil)
  set_trace_func(nil)

puts 'after get'
if resp.message == "OK"
  data.scan(/<img src="(.*?)"/) { |x| puts x }
end
#--------------------------------------------------------

daz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Kaplan  
View profile
 More options Jul 9 2005, 1:25 pm
Newsgroups: comp.lang.ruby
From: "Ken Kaplan" <kkap...@isher.com>
Date: Sun, 10 Jul 2005 02:25:35 +0900
Local: Sat, Jul 9 2005 1:25 pm
Subject: Re: HTTP.get problem
daz,

Thank you for your help, kind sir.

daz wrote:
> You *closed* ZA ?  (Not recommended ever, while online, BTW)

Yes, it was painful to turn it off, but I'm getting desperate.

daz wrote:
> Try running this modified version of your script and
> report which trace line number you reach.

I reach line 272. Unfortunately, except for the file names we picked, my
trace file (http://factoad.com/ruby/pptrace_x.txt) is identical to yours
(http://factoad.com/ruby/pptrace.txt) up to line 0272, where mine hangs and
yours continues. (Here's the diff file:
http://factoad.com/ruby/tracediff.txt. Here's the script:
http://factoad.com/ruby/io_test_trace.rb ).

It hangs when writing the get request string to a TCPsocket object.

Does anyone know why this might fail without raising an exception? Any
suggestions appreciated...

Ken

ruby 1.8.2 (2004-12-25) [i386-mswin32]
thread started with this email: http://factoad.com/ruby/email.txt


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill Pennington  
View profile
 More options Jul 9 2005, 2:08 pm
Newsgroups: comp.lang.ruby
From: Bill Pennington <b...@norcalkayakanglers.com>
Date: Sun, 10 Jul 2005 03:08:59 +0900
Local: Sat, Jul 9 2005 2:08 pm
Subject: Re: HTTP.get problem
I have not been following this thread closely so excuse me if I  
repeat advice from others. Since you are running windows and it looks  
like your are trying to access a raw socket maybe you have some kind  
of security setting that prevents raw socket access? I seem to recall  
some security update/recommended patch/tweak that prevented raw  
socket access from arbitrary programs.

On Jul 9, 2005, at 10:25 AM, Ken Kaplan wrote:

- Bill

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
daz  
View profile
 More options Jul 10 2005, 12:35 am
Newsgroups: comp.lang.ruby
From: "daz" <do...@d10.karoo.co.uk>
Date: Sun, 10 Jul 2005 05:35:24 +0100
Local: Sun, Jul 10 2005 12:35 am
Subject: Re: HTTP.get problem

Ken Kaplan wrote:

> [...]

> It hangs when writing the get request string to a TCPsocket object.

> Does anyone know why this might fail without raising an exception?
> Any suggestions appreciated...

I can't help, unfortunately.
I added -

  h.set_debug_output $stdout   # right after Net::HTTP.new

and got -

  opening connection to www.pragmaticprogrammer.com...
  opened
  <- "GET /index.html HTTP/1.1\r\nConnection: close\r\nHost: www.pragmaticprogrammer.com\r\n\r\n"
  -> "HTTP/1.1 200 OK\r\n"
  -> "Date: Sun, 10 Jul 2005 01:36:29 GMT\r\n"
  [...]

and (from your trace, thanks) you will be getting -

  opening connection to www.pragmaticprogrammer.com...
  opened
  [HANG]

(It's surprising that it doesn't time out, though.)

All I can suggest is that you try with a local server.
If you set this going in the background, you should
get a response from your browser at http://127.0.0.1/webrick :

                  <servlet.rb>
#-------------------------------------------------
require 'webrick'
include WEBrick

# Browser address: http://127.0.0.1/webrick

s = HTTPServer.new( :Port => 80 )

class HelloServlet < HTTPServlet::AbstractServlet
  def do_GET(req, res)
    # show request in response !
    res.body = req.to_s
    res['Content-Type'] = "text/plain"
  end
end
s.mount('/webrick', HelloServlet)

trap("INT") { s.shutdown }
STDOUT.sync=true
puts ' '*30 << '**********************************'
puts ' '*30 << '==  Ctrl+Break to close server  =='
puts ' '*30 << '**********************************'
s.start
#-------------------------------------------------

Then, if everything is OK of course, you could access
it from another Ruby session with your modified script:

#-------------------------------------------------
STDOUT.sync=true
require 'net/http'

h = Net::HTTP.new('127.0.0.1', 80)
h.set_debug_output STDOUT
resp, data = h.get('/webrick/xyz', nil)

puts '*'*30
if resp.message =~ /\AOK/
  print data
else
  puts 'ERROR ...'
  p resp.message
end
puts '*'*30
#-------------------------------------------------

It does seem like a problem you've got locally rather than
Ruby's Net library.  Please post back if you find the cause
or suspect 'Net' is at fault.

Good luck,

daz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ezra Zygmuntowicz  
View profile
 More options Jul 10 2005, 1:03 am
Newsgroups: comp.lang.ruby
From: Ezra Zygmuntowicz <e...@yakima-herald.com>
Date: Sun, 10 Jul 2005 14:03:14 +0900
Local: Sun, Jul 10 2005 1:03 am
Subject: Re: HTTP.get problem
I think you guys are having the same problem with windows and zone  
alarm that some people were having on the rails list. Zone alarm  
keeps ruby from working with sockets correctly. The only way they  
fixed this was by uninstalling zone alarm. Just turning it off didn't  
work but uninstalling it let ruby have its sockets back.

-Ezra
On Jul 9, 2005, at 9:40 PM, daz wrote:

-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
e...@yakima-herald.com
509-577-7732

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
daz  
View profile
 More options Jul 10 2005, 3:47 am
Newsgroups: comp.lang.ruby
From: "daz" <do...@d10.karoo.co.uk>
Date: Sun, 10 Jul 2005 08:47:21 +0100
Local: Sun, Jul 10 2005 3:47 am
Subject: Re: HTTP.get problem

Ezra Zygmuntowicz wrote:
> I think you guys are having the same problem with windows and zone
> alarm that some people were having on the rails list. Zone alarm
> keeps ruby from working with sockets correctly. The only way they
> fixed this was by uninstalling zone alarm. Just turning it off didn't
> work but uninstalling it let ruby have its sockets back.

> -Ezra

Thanks for the tip, Ezra.

This Jeff Nadeau blog entry is very interesting:
http://www.jfnadeau.com/node/13
Describes the Ruby under Windows problem !!    (Thanks, Jeff)

Anyone clued enough to contact him ?

Others with the problem:
http://forum.zonelabs.org/zonelabs/board/message?board.id=access&mess...
http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/146253

Ken,

I'm using ZA 2.6.362 (went back to an old version for a different
reason a while back) on 98se and it's OK.

Which Windows and ZA do you have ?

daz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Kaplan  
View profile
 More options Jul 10 2005, 9:20 pm
Newsgroups: comp.lang.ruby
From: "Ken Kaplan" <kkap...@isher.com>
Date: Mon, 11 Jul 2005 10:20:14 +0900
Local: Sun, Jul 10 2005 9:20 pm
Subject: Re: HTTP.get problem
Problem fixed!

Ezra Zygmuntowicz wrote:
> I think you guys are having the same problem with windows and zone
> alarm that some people were having on the rails list. Zone alarm
> keeps ruby from working with sockets correctly. The only way they
> fixed this was by uninstalling zone alarm. Just turning it off didn't
> work but uninstalling it let ruby have its sockets back.

> -Ezra

Bingo. I uninstalled ZoneAlarm and now I can HTTP#put to my heart's content.
I can also run gem --remote.

daz wrote:
> Which Windows and ZA do you have ?

I've got winxp sp2 with all the latest updates, and ZoneAlarm Suite 5-5-094,
with all their latest updates. The other computer that didn't have this
problem had the same winxp and ZoneAlarm updates, except that I had the paid
version and he had the free version.

I'll be trying it again with the free version, and contacting ZoneAlarm for
a workaround. I'll post again to this thread if I find one.

Thanks, folks.

Ken


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google