Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让Rubysspi 1.3.1与Ruby 1.9.3和Selenium Webdriver配合使用_Ruby_Proxy_Ntlm - Fatal编程技术网

如何让Rubysspi 1.3.1与Ruby 1.9.3和Selenium Webdriver配合使用

如何让Rubysspi 1.3.1与Ruby 1.9.3和Selenium Webdriver配合使用,ruby,proxy,ntlm,Ruby,Proxy,Ntlm,我最近从ruby 1.8.7迁移到ruby 1.9.3,在退出代理服务器时遇到了麻烦。从命令行安装gems可以正常工作,但在运行“apply_sspi_patch”之后,应该会对http.rb文件进行修补,并运行“test_patched_net_http.rb”测试文件,我看到: 1) Error: test_net_http(PatchedRubyTest): ArgumentError: Error occurred during proxy negotiation. req: nil

我最近从ruby 1.8.7迁移到ruby 1.9.3,在退出代理服务器时遇到了麻烦。从命令行安装gems可以正常工作,但在运行“apply_sspi_patch”之后,应该会对http.rb文件进行修补,并运行“test_patched_net_http.rb”测试文件,我看到:

  1) Error:
test_net_http(PatchedRubyTest):
ArgumentError: Error occurred during proxy negotiation. req: nil; res: #<Net::HTTPProxyAuthenticationRequired 407 Proxy Authentication Required readbody=true>; Original message: wrong number of arguments (1 for 0)
    C:/ruby/lib/ruby/gems/1.9.1/gems/rubysspi-1.3.1/lib/win32/sspi/http_proxy_patch.rb:76:in `request'
    test_patched_net_http.rb:33:in `block in test_net_http'
    test_patched_net_http.rb:32:in `test_net_http'
  • Ruby-Ruby 1.9.3p448(2013-06-27)[i386-mingw32]
  • Rubysspi-1.3.1
  • Selenium Webdriver-2.42.0

我通过修改gems\rubysspi-1.3.1\lib\win32\sspi\http\u proxy\u patch.rb文件缓解/消除了我的问题:

我在request方法中添加了一个retry(jretry),现在我再也看不到错误了

def request(req, body = nil, &block) # :yield: +response+
  unless started?
    start {
      req['connection'] ||= 'close'
      return request(req, body, &block)
    }
  end
  if proxy_user()
    unless use_ssl?
      req.proxy_basic_auth proxy_user(), proxy_pass()
    end
  end

  req.set_body_internal body
  begin_transport req
    req.exec @socket, @curr_http_version, edit_path(req.path)
    begin
      res = HTTPResponse.read_new(@socket)
    end while res.kind_of?(HTTPContinue)
    if tok = sspi_auth_required?(res)
      jretry = 2
      begin
        n = Win32::SSPI::NegotiateAuth.new
        res.reading_body(@socket, req.response_body_permitted?) { }
        end_transport req, res
        begin_transport req
        if proxy?
          req["Proxy-Authorization"] = "#{tok} #{n.get_initial_token(tok)}"
          req["Proxy-Connection"] = "Keep-Alive"
        else
          req["Authorization"] = "#{tok} #{n.get_initial_token(tok)}"
        end
        # Some versions of ISA will close the connection if this isn't present.
        req["Connection"] = "Keep-Alive"
        req.exec @socket, @curr_http_version, edit_path(req.path)
        begin
          res = HTTPResponse.read_new(@socket)
        end while res.kind_of?(HTTPContinue)
        if (proxy? && res["Proxy-Authenticate"]) || (! proxy? && res["WWW-Authenticate"])
          res.reading_body(@socket, req.response_body_permitted?) { }
          if proxy?
            req["Proxy-Authorization"] = "#{tok} #{n.complete_authentication res["Proxy-Authenticate"]}"
            req["Proxy-Connection"] = "Keep-Alive"
          else
            token = res["WWW-Authenticate"].split(" ").last
            req["Authorization"] = "#{tok} #{n.complete_authentication token}"
          end
          req["Connection"] = "Keep-Alive"
          req.exec @socket, @curr_http_version, edit_path(req.path)
          begin
            res = HTTPResponse.read_new(@socket)
          end while res.kind_of?(HTTPContinue)
        end
      rescue
        if jretry != 0
          jretry -= 1
          retry
        else
          exc = $!.exception("Error occurred during proxy negotiation. req: #{req["Proxy-Authorization"].inspect}; res: #{res.inspect}; Original message: #{$!.message}")
          exc.set_backtrace $!.backtrace
          raise exc
        end
      end
    end

    res.reading_body(@socket, req.response_body_permitted?) {
      yield res if block_given?
    }
  end_transport req, res

  res
end
def request(req, body = nil, &block) # :yield: +response+
  unless started?
    start {
      req['connection'] ||= 'close'
      return request(req, body, &block)
    }
  end
  if proxy_user()
    unless use_ssl?
      req.proxy_basic_auth proxy_user(), proxy_pass()
    end
  end

  req.set_body_internal body
  begin_transport req
    req.exec @socket, @curr_http_version, edit_path(req.path)
    begin
      res = HTTPResponse.read_new(@socket)
    end while res.kind_of?(HTTPContinue)
    if tok = sspi_auth_required?(res)
      jretry = 2
      begin
        n = Win32::SSPI::NegotiateAuth.new
        res.reading_body(@socket, req.response_body_permitted?) { }
        end_transport req, res
        begin_transport req
        if proxy?
          req["Proxy-Authorization"] = "#{tok} #{n.get_initial_token(tok)}"
          req["Proxy-Connection"] = "Keep-Alive"
        else
          req["Authorization"] = "#{tok} #{n.get_initial_token(tok)}"
        end
        # Some versions of ISA will close the connection if this isn't present.
        req["Connection"] = "Keep-Alive"
        req.exec @socket, @curr_http_version, edit_path(req.path)
        begin
          res = HTTPResponse.read_new(@socket)
        end while res.kind_of?(HTTPContinue)
        if (proxy? && res["Proxy-Authenticate"]) || (! proxy? && res["WWW-Authenticate"])
          res.reading_body(@socket, req.response_body_permitted?) { }
          if proxy?
            req["Proxy-Authorization"] = "#{tok} #{n.complete_authentication res["Proxy-Authenticate"]}"
            req["Proxy-Connection"] = "Keep-Alive"
          else
            token = res["WWW-Authenticate"].split(" ").last
            req["Authorization"] = "#{tok} #{n.complete_authentication token}"
          end
          req["Connection"] = "Keep-Alive"
          req.exec @socket, @curr_http_version, edit_path(req.path)
          begin
            res = HTTPResponse.read_new(@socket)
          end while res.kind_of?(HTTPContinue)
        end
      rescue
        if jretry != 0
          jretry -= 1
          retry
        else
          exc = $!.exception("Error occurred during proxy negotiation. req: #{req["Proxy-Authorization"].inspect}; res: #{res.inspect}; Original message: #{$!.message}")
          exc.set_backtrace $!.backtrace
          raise exc
        end
      end
    end

    res.reading_body(@socket, req.response_body_permitted?) {
      yield res if block_given?
    }
  end_transport req, res

  res
end