4

伙计们!我收到以下错误消息,我不知道该怎么做。这是一个已知的 net-ldap 错误吗?我尝试更新我的 gem,我已经在互联网上寻找更多信息。第一部分没问题,我从我的 ldap 数据库中获取了我的数据,但最后发生了这个错误。

/usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:23:in encode': "\x8E" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:23:in raw_utf8_encoded' 来自 /usr/local/lib/ ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:15:in to_ber' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1396:in block in search' 来自 /usr/local/lib/ruby/gems/1.9 .1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1367:in loop' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1367:in search' 来自 /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3。 1/lib/net/ldap.rb:637:在“搜索”中

这里是我的代码:

require 'rubygems'
require 'net/ldap'

ldap = Net::LDAP.new
ldap.host = 'xxxxxx'
ldap.authenticate "cn=admin, dc=xxxx, dc=xxxxx, dc=de", "xxxxx!"
#puts ldap.bind
if ldap.bind
  # authentication succeeded
else
  # authentication failed
 # p ldap.get_operation_result
end


filter = Net::LDAP::Filter.eq("uid", "*")
treebase = "xxxxx, dc=xxxxxx, dc=de"

ldap.search(:base => treebase, :filter => filter) do |entry|
  puts "DN: #{entry.dn}"
  entry.each do |attribute, values|
    puts "   #{attribute}:"
    values.each do |value|
      puts "      --->#{value}"
    end
  end
end
4

1 回答 1

3

net-ldap [1],[2],[3],[4] 的 v0.3.1 中有很多编码问题。已经合并了几个补丁,但遗憾的是,这个伟大的项目似乎被半放弃了,并且没有将更改推送到 ruby​​gems。直接从 github 使用它对我来说效果很好,如果你使用的是 bundler,在你的 Gemfile 中粘贴这样的东西很容易:

gem "net-ldap", :git => "git://github.com/ruby-ldap/ruby-net-ldap.git", :ref => '8a182675f4'

1 - https://github.com/ruby-ldap/ruby-net-ldap/pull/41
2 - https://github.com/ruby-ldap/ruby-net-ldap/pull/44
3 - https: //github.com/ruby-ldap/ruby-net-ldap/pull/64
4 - https://github.com/ruby-ldap/ruby-net-ldap/pull/55

于 2013-04-29T19:02:40.160 回答