gpt4 book ai didi

ruby-on-rails - Mechanize 和 HTTParty 中的 "Hostname does not match the server certificate"错误

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:12 26 4
gpt4 key购买 nike

偶尔,当我访问带有 HTTPPartyMechanize 的网站时,我会收到此错误:

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

我可以看到 there is a workaround如果您使用 open 方法,但我不确定如何利用上述 gems。

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'

HTTPParty 的堆栈跟踪:

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'

最佳答案

对于 Mechanize,这应该将验证 SSL 设置为无

agent = Mechanize.new
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE

对于 HTTParty,有 verify: 选项看到这个问题How do I make HTTParty ignore SSL?

如果你想一般地设置它,使用这个肮脏的技巧:

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

关于ruby-on-rails - Mechanize 和 HTTParty 中的 "Hostname does not match the server certificate"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com