ruby on rails - "Hostname does not match the server certificate" error in Mechanize and HTTParty -


occationally, when visit website httparty or mechanize, error:

hostname "www.example.com" not match server certificate 

i can see there workaround if use open method, i'm not sure how leverage above gems.

stacktrace mechanize:

agent = mechanize.new agent.read_timeout              = 180 agent.open_timeout              = 180 agent.user_agent_alias          = 'mac safari' agent.redirect_ok               = :all agent.follow_meta_refresh       = :anywhere agent.follow_meta_refresh_self  = true agent.get("https://some-domain.com") /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/openssl/ssl.rb:232:in `post_connection_check' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:925:in `connect' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:863:in `do_start' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:858:in `start' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:965:in `reset' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:628:in `connection_for' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mechanize-2.7.4/lib/mechanize/http/agent.rb:267:in `fetch' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mechanize-2.7.4/lib/mechanize.rb:464:in `get' 

stacktrace httparty:

httparty.get("https://some-domain.com") /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/openssl/ssl.rb:232:in `post_connection_check' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:925:in `connect' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:863:in `do_start' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:852:in `start' /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:1375:in `request' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty/request.rb:117:in `perform' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty.rb:545:in `perform_request' /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty.rb:476:in `get' 

for mechanize should set verify ssl none

agent = mechanize.new agent.verify_mode = openssl::ssl::verify_none 

for httparty there's verify: option see question how make httparty ignore ssl?

if want set generally, use dirty trick:

openssl::ssl::verify_peer = openssl::ssl::verify_none 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -