# Net LDAP problem (no attrs or get\_attributes methods)

**URL:** <https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000>\
**Category:** Ruby\
**Created:** [October 27, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000 "2009-10-27T19:56:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 27, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/1 "2009-10-27T19:56:21Z")

</div>

So I am having difficulty getting the attributes for an LDAP entry. If  
I  
check for specific attributes by name that works fine. However when I  
try  
the following:

ldap.search(:base =\> base, :filter =\> address\_only\_filter,  
:return\_result =\>  
false) do |entry|  
p entry.dn  
p entry.attrs  
puts “\n\n”  
end

I get the following error:

/Library/Ruby/Gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/ldap/entry.rb:152:in  
‘method\_missing’: undefined method ‘attrs’ (NoMethodError)

I get the same NoMethodError when I try get\_attributes.

I am getting a Net::LDAP::Entry object back from the search as verified  
by  
changing the p entry.attrs to p entry.class

Anyone else run across this?

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I canâ€™t hear a word youâ€™re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 28, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/2 "2009-10-28T21:03:46Z")

</div>

ldap.search(base, scope, filter, attrs) { |entry|  
p entry.dn  
p entry.attrs  
}

Does the above work for you?

Regards,

- Mac

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 29, 2009, 5:35pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/3 "2009-10-29T17:35:25Z")

</div>

Nope, same error. I passed “\*” to the attrs argument.

On Wed, Oct 28, 2009 at 2:03 PM, Michael L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I canâ€™t hear a word youâ€™re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 29, 2009, 7:41pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/4 "2009-10-29T19:41:53Z")

</div>

On Thu, Oct 29, 2009 at 12:28 PM, Michael L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

The docs say string or array of strings. Tried it with :attributes =\>  
[]  
and I get the same error. I also tried reinstalling the gem but that  
didn’t  
help.

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I canâ€™t hear a word youâ€™re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 29, 2009, 8:54pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/5 "2009-10-29T20:54:29Z")

</div>

> The docs say string or array of strings. Tried it with :attributes =\>  
> []  
> and I get the same error. I also tried reinstalling the gem but that  
> didn’t  
> help.

What gem are you using? ruby-net-ldap? via require ‘net/ldap’?  
Might help to post more of your code so I can understand the whole  
picture of things…

p entry.attrs is invalid as it isn’t a method per’se… hence the  
NoMethodError.  
attrs is like you said a string or array of strings.

It should be used via connection.add(“dc=localhost, dc=localdomain”,  
entry)

Regards,

- Mac

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 29, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/6 "2009-10-29T19:28:26Z")

</div>

Glen H. wrote:

> Nope, same error. I passed “\*” to the attrs argument.

Well, attrs should be an array I believe, try initializing it as such:  
attrs = []  
and see what happens.

Regards,

- Mac

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 29, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/net-ldap-problem-no-attrs-or-get-attributes-methods/178000/7 "2009-10-29T21:57:05Z")

</div>

On Thu, Oct 29, 2009 at 1:54 PM, Michael L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Here is the code in its entirety:

require ‘rubygems’  
require ‘net/ldap’

ldap = Net::LDAP.new :host =\> , :port =\> 389, :auth =\> { :method =\>  
:simple,  
:username =\> “”, :password =\> “” }

address\_only\_filter = Net::LDAP::Filter.pres(“mailForwardingAddress”) &  
~(Net::LDAP::Filter.eq(“mailDeliveryOption”, “forward”))

base = “ou=People,o=cnm.edu,o=cp”

ldap.search(:base =\> base, :scope =\>  
Net::LDAP::SearchScope\_WholeSubtree,  
:filter =\> address\_only\_filter, :attributes =\> “\*”) do |entry|  
p entry.dn  
p entry.attrs  
end

I’ve removed the credentials and the host IP intentionally. Calling a  
specific attribute on the object works just fine. It just breaks when I  
try  
to request all of them. I figured it would be the easiest way to ensure  
I  
only remove the attribute I’m interested in since not all records are  
sure  
to have the same attributes.

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I canâ€™t hear a word youâ€™re saying.”

-Greg Graffin (Bad Religion)
