I poked around the web a little and didn''t run across how to use https when it asks for certificate validation. I''m trying to connect to devices that don''t have valid certificates, and in this case, I don''t care if they are or not. So when I use my browser to ge to the site, firefox asks me to allow the certificate, then one other question, then I get the authentication screen. How do I get mechanize to just say OK to the first two pop up screens? Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Wed, Feb 07, 2007 at 01:14:26PM -0900, barsalou wrote:> I poked around the web a little and didn''t run across how to use https > when it asks for certificate validation. > > I''m trying to connect to devices that don''t have valid certificates, > and in this case, I don''t care if they are or not. > > So when I use my browser to ge to the site, firefox asks me to allow > the certificate, then one other question, then I get the authentication > screen. > > How do I get mechanize to just say OK to the first two pop up screens? > > Mike B.IIRC, mechanize should accept invalid certs. Can you send the exact error you get? -- Aaron Patterson http://tenderlovemaking.com/
Quoting Aaron Patterson <aaron_patterson at speakeasy.net>:> > IIRC, mechanize should accept invalid certs. Can you send the exact > error you get? > > --I may have mispoke here...I''m doing more testing...thanks for getting back to me. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Quoting Aaron Patterson <aaron_patterson at speakeasy.net>:> IIRC, mechanize should accept invalid certs. Can you send the exact > error you get? >OK, after some more testing, I consistently got this error: /usr/lib/ruby/1.8/net/http.rb:1049:in `request'': Unhandled response (WWW::Mechanize::ResponseCodeError) from /usr/lib/ruby/1.8/net/http.rb:2104:in `reading_body'' from /usr/lib/ruby/1.8/net/http.rb:1048:in `request'' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:337:in `fetch_page'' from /usr/lib/ruby/1.8/net/http.rb:545:in `start'' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:290:in `fetch_page'' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:136:in `get'' from ctsdisable.rb:15 Using: lynx https://192.168.11.3 I got: SSL error:self signed certificate-Continue? (y) then: SSL error:host(192.168.11.3)!=cert(192.168.168.2)-Continue? (y) It goes through this sequence twice, then asks for the username/password pair. Code looks like this: agent = WWW::Mechanize.new agent.user_agent_alias = ''Mac Safari'' agent.basic_auth(username, password) page = agent.get("https://192.168.11.3") Hope this helps. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Mon, Feb 12, 2007 at 10:09:22PM -0900, barsalou wrote:> Quoting Aaron Patterson <aaron_patterson at speakeasy.net>: > > > IIRC, mechanize should accept invalid certs. Can you send the exact > > error you get? > > > > OK, after some more testing, I consistently got this error: > > /usr/lib/ruby/1.8/net/http.rb:1049:in `request'': Unhandled response > (WWW::Mechanize::ResponseCodeError) > from /usr/lib/ruby/1.8/net/http.rb:2104:in `reading_body'' > from /usr/lib/ruby/1.8/net/http.rb:1048:in `request'' > from > /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:337:in > `fetch_page'' > from /usr/lib/ruby/1.8/net/http.rb:545:in `start'' > from > /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:290:in > `fetch_page'' > from > /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:136:in > `get'' > from ctsdisable.rb:15This doesn''t look like a problem with the ssl cert. It looks like the server sent back a response code that mechanize can''t handle. Can you try catching the exception and printing out the response code, ie: begin mech = WWW::Mechanize.new ... rescue WWW::Mechanize::ResponseCodeError => ex puts ex.response_code end Also, it looks like you are running an old version of mechanize. Are you able to upgrade? Upgrading may fix your issue. -- Aaron Patterson http://tenderlovemaking.com/
Looks like it is returning a 401. I wonder if including the username/password pair in the URL would help? How would I do that anyway? I tried https://username:password at 192.168.11.3 and that didn''t seem to work...any ideas? Additionally, I did upgrade. Mike B. Quoting Aaron Patterson <aaron_patterson at speakeasy.net>:> On Mon, Feb 12, 2007 at 10:09:22PM -0900, barsalou wrote: >> Quoting Aaron Patterson <aaron_patterson at speakeasy.net>: >> >> > IIRC, mechanize should accept invalid certs. Can you send the exact >> > error you get? >> > >> >> OK, after some more testing, I consistently got this error: >> >> /usr/lib/ruby/1.8/net/http.rb:1049:in `request'': Unhandled response >> (WWW::Mechanize::ResponseCodeError) >> from /usr/lib/ruby/1.8/net/http.rb:2104:in `reading_body'' >> from /usr/lib/ruby/1.8/net/http.rb:1048:in `request'' >> from >> /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:337:in >> `fetch_page'' >> from /usr/lib/ruby/1.8/net/http.rb:545:in `start'' >> from >> /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:290:in >> `fetch_page'' >> from >> /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:136:in >> `get'' >> from ctsdisable.rb:15 > > This doesn''t look like a problem with the ssl cert. It looks like the > server sent back a response code that mechanize can''t handle. Can you > try catching the exception and printing out the response code, ie: > > begin > mech = WWW::Mechanize.new > ... > rescue WWW::Mechanize::ResponseCodeError => ex > puts ex.response_code > end > > Also, it looks like you are running an old version of mechanize. Are > you able to upgrade? Upgrading may fix your issue. > > -- > Aaron Patterson > http://tenderlovemaking.com/ > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Tue, Feb 13, 2007 at 11:37:44AM -0900, Mike wrote:> Looks like it is returning a 401. I wonder if including the > username/password pair in the URL would help? How would I do that > anyway? I tried https://username:password at 192.168.11.3 and that didn''t > seem to work...any ideas?The username:password scheme doesn''t work right now. Just set them with the basic auth method. Hmmm... 401 means unauthorized. So, either the username and password is incorrect, or there is a bug in the authorization code. Do you know what type of authorization is being used, digest, or basic? -- Aaron Patterson http://tenderlovemaking.com/
OK...that really torks me. I checked a bunch of times on the user/pass pair...and I had it wrong! Crap, I hate that! :) Thanks for sticking with me. I guess we did find that Mechanzie wasn''t handling the 401 though... :) Mike B. Quoting Aaron Patterson <aaron_patterson at speakeasy.net>:> On Mon, Feb 12, 2007 at 10:09:22PM -0900, barsalou wrote: >> Quoting Aaron Patterson <aaron_patterson at speakeasy.net>: >> >> > IIRC, mechanize should accept invalid certs. Can you send the exact >> > error you get? >> > >> >> OK, after some more testing, I consistently got this error: >> >> /usr/lib/ruby/1.8/net/http.rb:1049:in `request'': Unhandled response >> (WWW::Mechanize::ResponseCodeError) >> from /usr/lib/ruby/1.8/net/http.rb:2104:in `reading_body'' >> from /usr/lib/ruby/1.8/net/http.rb:1048:in `request'' >> from >> /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:337:in >> `fetch_page'' >> from /usr/lib/ruby/1.8/net/http.rb:545:in `start'' >> from >> /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:290:in >> `fetch_page'' >> from >> /usr/lib/ruby/gems/1.8/gems/mechanize-0.5.1/lib/mechanize.rb:136:in >> `get'' >> from ctsdisable.rb:15 > > This doesn''t look like a problem with the ssl cert. It looks like the > server sent back a response code that mechanize can''t handle. Can you > try catching the exception and printing out the response code, ie: > > begin > mech = WWW::Mechanize.new > ... > rescue WWW::Mechanize::ResponseCodeError => ex > puts ex.response_code > end > > Also, it looks like you are running an old version of mechanize. Are > you able to upgrade? Upgrading may fix your issue. > > -- > Aaron Patterson > http://tenderlovemaking.com/ > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Tue, Feb 13, 2007 at 12:34:10PM -0900, barsalou wrote:> OK...that really torks me. I checked a bunch of times on the user/pass > pair...and I had it wrong! Crap, I hate that! :) > > Thanks for sticking with me.No problem! I''m glad to help.> I guess we did find that Mechanzie wasn''t handling the 401 though... :)Yes. Mechanize does throw an exception on 401 responses. I personally think that is good. I would want an exception thrown if the user/pass was changed on the server, wouldn''t you? Maybe I could put better messages in the exception though...... -- Aaron Patterson http://tenderlovemaking.com/
Quoting Aaron Patterson <aaron_patterson at speakeasy.net>:> Yes. Mechanize does throw an exception on 401 responses. I personally > think that is good. I would want an exception thrown if the user/pass > was changed on the server, wouldn''t you? Maybe I could put better > messages in the exception though......I think this is fine, I just need to remember to write the rescue code. :) I really like this software. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Things are going smoother now and I notice that the first time I hit the site, it always returns the 401. This is similar in action to the lynx example I talked about earlier. I assume that all I need to do is a retry for that connection and all should be well. Would extending mechanize to do a single retry for a 401 be the best option for me? Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Wed, Feb 14, 2007 at 09:09:29AM -0900, barsalou wrote:> > Things are going smoother now and I notice that the first time I hit > the site, it always returns the 401. This is similar in action to the > lynx example I talked about earlier. I assume that all I need to do is > a retry for that connection and all should be well.Weird. Are you setting the user and password before you make the request?> Would extending mechanize to do a single retry for a 401 be the best > option for me?The best option would be to figure out why you have to retry the request, and fix that. Can you set a the logger on your mechanize object and send it in (making sure to censor sensitive info of course)? -- Aaron Patterson http://tenderlovemaking.com/
Quoting Aaron Patterson <aaron_patterson at speakeasy.net>:> On Wed, Feb 14, 2007 at 09:09:29AM -0900, barsalou wrote: >> >> Things are going smoother now and I notice that the first time I hit >> the site, it always returns the 401. This is similar in action to the >> lynx example I talked about earlier. I assume that all I need to do is >> a retry for that connection and all should be well. > > Weird. Are you setting the user and password before you make the > request?I''ll double check this...> >> Would extending mechanize to do a single retry for a 401 be the best >> option for me? > > The best option would be to figure out why you have to retry the > request, and fix that. Can you set a the logger on your mechanize > object and send it in (making sure to censor sensitive info of course)? > >Not sure how to ''set the logger'' on my mechanize object...but would gladly do it, if I knew how. :) Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
> Not sure how to ''set the logger'' on my mechanize object...but would > gladly do it, if I knew how. :) > > Mike B.If your local IT department doesn''t object, WireShark (formerly Ethereal) is a great way to analyze what''s going on at a packet level: http://www.wireshark.org/ -Chris
On Wed, Feb 14, 2007 at 01:06:47PM -0900, barsalou wrote:> Not sure how to ''set the logger'' on my mechanize object...but would > gladly do it, if I knew how. :)Sure. Here''s an example: require ''rubygems'' require ''mechanize'' require ''logger'' mech = WWW::Mechanize.new { |m| m.log = Logger.new(''out.log'') } page = mech.get(''http://google.com/'') ... This will write useful debugging info to a file called ''out.log''. -- Aaron Patterson http://tenderlovemaking.com/
Quoting Chris McMahon <christopher.mcmahon at gmail.com>:>> Not sure how to ''set the logger'' on my mechanize object...but would >> gladly do it, if I knew how. :) >> >> Mike B. > > > If your local IT department doesn''t object, WireShark (formerly > Ethereal) is a great way to analyze what''s going on at a packet level: > http://www.wireshark.org/Interesting...I hadn''t considered that. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.