I recently started trying to implement a LDAP-based login system in my
Rails application, but whenever I try to run a basic LDAP query I get the
following error:
Encoding::UndefinedConversionError: "\x82" from ASCII-8BIT to UTF-8
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ber/core_ext/string.rb:23:in
> `encode'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ber/core_ext/string.rb:23:in
> `raw_utf8_encoded'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ber/core_ext/string.rb:15:in
> `to_ber'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ldap.rb:1396:in
> `block in search'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ldap.rb:1367:in
> `loop'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ldap.rb:1367:in
> `search'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net /ldap.rb:637:in
> `search'
> from C:/Documents and Settings/meyer.a/My
> Documents/Workspace/Training Hub/Training Hub
> Workspace/training_hub/app/models/user.rb:32:in `all'
> from (irb):29
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rai ls/commands/console.rb:47:in
> `start'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rai ls/commands/console.rb:8:in
> `start'
> from
> c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rai ls/commands.rb:41:in
> `<top (required)>'
> from script/rails:6:in `require'
> from script/rails:6:in `<main>'
It seems to be triggered whenever net-ldap hits a certain record in the
ldap database (though I can't really tell which one). Here's the code I'm
running that triggers the error. It always gets to a certain point and then
errors out:
test = LDAP.search(
> base: BASE_ROOT, # This is defined elsewhere in my code.
> attributes: ["mail"],
> filter: Net::LDAP::Filter.eq("objectClass", "person"),
> return_result: true,
> size:300
> ) do |entry|
> puts "DN: #{entry.dn}"
> entry.each do |attribute, values|
> puts " #{attribute}:"
> values.each do |value|
> puts " --->#{value}"
> end
> end
> end
Is this a bug? Or is there something I'm doing wrong?