django-auth-ldap with python3?

2,155 views
Skip to first unread message

Milt Epstein

unread,
Nov 28, 2013, 3:34:22 PM11/28/13
to django-a...@googlegroups.com, Milt Epstein
Hi. I'm trying to use django-auth-ldap with python3. I recently
installed Python 3.3.3 and Django 1.6. I downloaded and installed the
python3 branch of django-auth-ldap (from 2013-08-14, marked as version
1.1.4?), and that seemed to go OK, although there was an error at the
end of the install, I think because it was trying to install
python-ldap, which I don't believe has a python3 version. Then I set
up some config to use django-auth-ldap, and when I tried to run it, it
came back with an ImportError, No module named 'ldap', again I believe
running into the lack of a python3 version of python-ldap.

So, can I use django-auth-ldap with python 3.3? What do I need to do?

If someone created this python3 version of django-auth-ldap, that
should mean they were able to actually use it with python3, no?

I see that there's a python3-ldap package, and I installed that, but I
presume that's a totally different library/API than python-ldap.

Note: I'm an experienced developer, but relatively new to python. I
don't mind getting my hands dirty a bit, say, if I have to do some
recoding. But I would need some fairly specific comments to get me
going on that, because my knowledge of python isn't too deep yet.

Could I, say, make python-ldap work with python3? I'd think not -- if
it was that easy, surely it'd be done by now. Is there a python3
version of python-ldap lurking out there somewhere? I couldn't find
one.

Could I recode django-auth-ldap to work with python3-ldap, perhaps via
some intermediate/abstraction layer?

Other possibilities?

Thanks.

Milt Epstein
Applications Developer
Graduate School of Library and Information Science (GSLIS)
University of Illinois at Urbana-Champaign (UIUC)
meps...@illinois.edu

Peter Sagerson

unread,
Nov 28, 2013, 5:54:12 PM11/28/13
to django-a...@googlegroups.com
Hi Milt,

Sadly, django-auth-ldap doesn't support python 3 due, as you observed, to the lack of an LDAP library. Python-ldap still hasn't made it to python 3 and python3-ldap, last I checked in on it, was still in development. The python3 branch of django-auth-ldap is just a few changes contributed by someone else; I didn't look closely at them, but I suspect it was just enough to satisfy 2to3.

If python3-ldap has matured enough, then it's possible that all of the pieces are now in place to get django-auth-ldap running on 3. I should take another look at it soon, but you might find it worthwhile to try cobbling something together in the meantime. If so, I'd be interested to hear how it goes.

Thanks,
Peter
> --
> You received this message because you are subscribed to the Google Groups "django-auth-ldap" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-auth-ld...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

signature.asc

Milt Epstein

unread,
Nov 29, 2013, 11:02:46 PM11/29/13
to django-a...@googlegroups.com
Peter,

OK, thanks for the response. I think I'll have a go at getting
django-auth-ldap working with python3-ldap. I sent the author of that
module a note -- he says it's compliant with many of the relevant
RFCs, he's not aware of any problems with it, and he's still actively
working on maintaining/augmenting it.

Milt

Bradford wade

unread,
Mar 10, 2014, 9:54:41 AM3/10/14
to django-a...@googlegroups.com, meps...@illinois.edu
Did you get anywhere with this? I'm encountering the exact same issue: trying to use LDAP for my authentication backend in Django on Python 3.

Milt Epstein

unread,
Mar 11, 2014, 3:31:56 PM3/11/14
to Bradford wade, django-a...@googlegroups.com
No, unfortunately I didn't get very far with that. It got
back-burnered, and hasn't come to the forefront again.

I did get some authentication stuff set up with Basic Auth and CAS
(which we already use on other sites), using
RemoteUserBackend/RemoteUserMiddleware, and that sufficed for what I
needed at the time.

I do hope to work on this further (or make use of someone else's work
on it, if they get to it first), but it hasn't come up as something we
need yet, nor have I had the time.

As I had said, python3-ldap seems to be sufficient and robust. But,
as I recall, it was somewhat structurally different than the ldap
already being used by django-auth-ldap, so it wasn't just a drop in
replacement. But it might not be too difficult to get it going
(especially for someone experienced with Python and/or Django, which I
don't count myself as, yet :-).

Please let me know if you end up working on this.

Milt
> > > On Nov 28, 2013, at 12:34 PM, Milt Epstein <meps...@illinois.edu<javascript:>>
> > > > meps...@illinois.edu <javascript:>
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups "django-auth-ldap" group.
> > > > To unsubscribe from this group and stop receiving emails from it, send
> > an email to django-auth-ld...@googlegroups.com <javascript:>.
> > > > For more options, visit https://groups.google.com/groups/opt_out.
> > >
> > >
> >
> > Milt Epstein
> > Applications Developer
> > Graduate School of Library and Information Science (GSLIS)
> > University of Illinois at Urbana-Champaign (UIUC)
> > meps...@illinois.edu <javascript:>

Peter Sagerson

unread,
Mar 11, 2014, 4:17:47 PM3/11/14
to django-a...@googlegroups.com
I might actually get to this over the summer, when my day job will (hopefully) be in remission. Nothing's certain yet. If anyone wants to get a head start, by all means feel free.

One of the big open questions right now is testing. The django-auth-ldap test infrastructure was recently spun off as mockldap, which is designed to be a full python-ldap mocking layer (with individual methods being implemented as needed). Will we need the same for python3-ldap? I wonder if the python3-ldap author would be interested in incorporating mocking facilities directly?

Having perused the python3-ldap code a little while back, I'm also a little concerned about the string decoding policy. I haven't verified this empirically, but it seems like there's an assumption baked into the lowest levels that all attribute values are utf8-encoded strings. django-auth-ldap currently has a bit of a hack in place to try and decode all attribute values as utf8, but leave them alone if that fails. I assume the only way to get this right is to obtain the schema and selectively decode values based on their defined types. I haven't looked into this too deeply yet, but I wouldn't be surprised if there were a chunk of python3-ldap work required to avoid mangling binary attributes.

I also have half a mind to convert all of the settings to primitive types (strings, lists, dicts, etc.) for consistency with Django conventions. Other backward-incompatible suggestions are welcome at this point, if anyone has a pet peeve.

Thanks,
Peter
> To unsubscribe from this group and stop receiving emails from it, send an email to django-auth-ld...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

pytho...@gmail.com

unread,
Mar 13, 2014, 11:50:25 AM3/13/14
to django-a...@googlegroups.com
Hello Peter,
I'm the author of the python3-ldap library. Thanks for looking at my code. I've been working on python3-ldap since last summer, starting completely from scratch. I've been using python-ldap for a long time and in python3-ldap I tried to avoid the bottlenecks I found in it. So I started reading the whole set the latest RFCs regarding LDAP and developed the code in a different (and more suitable for my needs) way than python-ldap. It's not a wrapper to the openldap client, but it's a pure python3 library strictly conformant to all aspects of RFCs. It depends only on the pyasn1 package and doesn't need any compiler or binary installation to be used on Linux or Windows. It has a pluggable communication strategy feature (there are 4 different now) and it's a bit slower than python-ldap because of its 'pure' nature. It's even compatible with python 2.6 and 2.7. I'm working on making it PEP8 compliant.

Regarding your concerns about the utf-8 nature of the attribute values, this is specified in the RFC itself: all string used at the communication level must be utf-8 encoded. When you need to send binary data you must escape it as defined in the RFC. When you're receiving data you get always get two attributes in the response object: the 'value' attribute (that is encoded in utf-8) and the 'raw_value' that is the binary (bytearray object) representation of the data received over the socket, without any transformation. So you can get the data in the format you need.

Regarding the mocking option it should be included as a different communication strategy without much effort.

Now I'm working on a"restartable" strategy to be used in long standing applications (as application and web servers) that should be capable of reconnecting (at the socket layer) when the server is down or network is broken. I'm working on an "ldappool" feature for the same kind of applications.

I would be glad to help you in deciding if python3-ldap is a good option for your project.
Let me know if you need any other information or have any idea on how to enhance the library.

Bye,
Giovanni

Peter Sagerson

unread,
Mar 13, 2014, 1:28:01 PM3/13/14
to django-a...@googlegroups.com
Hey Giovanni,

Good to hear from you. Thanks for the clarification on encoding--I know some of our users have had issues with this in the past, but it's quite possible they were using non-compliant LDAP servers. I'm happy to let that be someone else's problem.

This library has been needed for some time, so thanks for taking it on. Hopefully I'll have time in a few months to really dig into it.

Thanks,
Peter
signature.asc

aymeric....@oscaro.com

unread,
Mar 24, 2014, 6:33:08 PM3/24/14
to django-a...@googlegroups.com
Hello,

I would like to use django-auth-ldap on Python 3 too. I've sumbitted two pull requests:
1) https://bitbucket.org/psagers/mockldap/pull-request/7/add-compatibility-with-python-33/diff
2) https://bitbucket.org/psagers/django-auth-ldap/pull-request/14/add-compatibility-with-python-33/diff

The first one should be almost ready for commit. I'm a little less sure about the second one; a test fails and I'm not sure why. At least you can run tox and see that we're almost there!

I've chosen to target Python 3.3+ to avoid having to deal with u"..." literals, thanks to PEP 414 (and against the guidelines I've written for Django -- doh!)

All this relies on a Python 3 version of python-ldap developed by Raphaël Barrois and slightly improved by myself: https://github.com/rbarrois/python-ldap/pull/1. This is the part I'm most worried about. The python-ldap code is really old -- think Python 1.5. Switching to a more modern LDAP library would probably be a good idea.

I hope this helps,

--
Aymeric.

Peter Sagerson

unread,
Mar 25, 2014, 12:11:15 PM3/25/14
to django-a...@googlegroups.com
Nice, thanks. Ordinarily, reliance on patches over patches over unmaintained libraries isn't very appealing, but since it seems clear that python-ldap isn't the way forward for 3.x, I'm more inclined to take any hack that doesn't break 2.x and call it experimental. Is the intention here to have me cut a release of django-auth-ldap and put a note in the documentation about how one might get it to work on 3.3, but no promises?

I'm frantically trying to get another set of releases out before flying down to Macworld tomorrow, but I should have time next week to play with this.

Thanks,
Peter
signature.asc

Aymeric AUGUSTIN

unread,
Mar 25, 2014, 12:31:09 PM3/25/14
to django-a...@googlegroups.com
Hi Peter,

On 25 Mar 2014, at 17:11, Peter Sagerson <psa...@ignorare.net> wrote:

> Nice, thanks. Ordinarily, reliance on patches over patches over unmaintained libraries isn't very appealing

I couldn’t agree more. My proposal is in the spirit of “practicality beats purity”.

> but since it seems clear that python-ldap isn't the way forward for 3.x, I'm more inclined to take any hack that doesn't break 2.x and call it experimental.

Note that my PR requires at least Python 2.6 — I forgot to reflect this in the documentation. It’s hard to write code that works both on Python 2.5 and Python 3.x because the `except` syntax changed.

Only Django 1.4 still supports Python 2.5. I find it fair to drop support for Python 2.5 in newer versions of libraries and tell users that if they’re stuck with Django 1.4 and Python 2.5, they should use an older version.

> Is the intention here to have me cut a release of django-auth-ldap and put a note in the documentation about how one might get it to work on 3.3, but no promises?

Yes, that would be helpful, if only to prevent people from forking django-auth-ldap to add support for Python 3.

The docs should just say “Since python-ldap doesn’t support Python 3, you’ll have to use an unofficial fork such as https://github.com/rbarrois/python-ldap/tree/py3”. I’m working with Raphaël to get my patches merged there and drop my fork.

Thank you,

--
Aymeric.

Peter Sagerson

unread,
Mar 31, 2014, 4:12:55 PM3/31/14
to django-a...@googlegroups.com
This is looking good. I merged the two pull requests and made a couple small fixes. The cidict issue is because we weren't using the string-decoding hack for Python 3. I gather that the python-ldap port automatically decodes utf-8 values to strings now? I updated _DeepStringCoder to ignore unicode strings in a py3-safe way so that we can still use it to get the cidict conversion. Incidentally, I'm not sure why python-ldap isn't using cidict for attribute dictionaries on its own.

If you pull the latest public changes to mockldap, all of the tests should be passing. Take it for a spin and if you think it's usable, I'll post some builds.

Thanks,
Peter


On Mar 25, 2014, at 9:31 AM, Aymeric AUGUSTIN <aymeric....@oscaro.com> wrote:

> Hi Peter,
>
> On 25 Mar 2014, at 17:11, Peter Sagerson <psa...@ignorare.net> wrote:
>
>> Nice, thanks. Ordinarily, reliance on patches over patches over unmaintained libraries isn't very appealing
>
> I couldn't agree more. My proposal is in the spirit of "practicality beats purity".
>
>> but since it seems clear that python-ldap isn't the way forward for 3.x, I'm more inclined to take any hack that doesn't break 2.x and call it experimental.
>
> Note that my PR requires at least Python 2.6 -- I forgot to reflect this in the documentation. It's hard to write code that works both on Python 2.5 and Python 3.x because the `except` syntax changed.
>
> Only Django 1.4 still supports Python 2.5. I find it fair to drop support for Python 2.5 in newer versions of libraries and tell users that if they're stuck with Django 1.4 and Python 2.5, they should use an older version.
>
>> Is the intention here to have me cut a release of django-auth-ldap and put a note in the documentation about how one might get it to work on 3.3, but no promises?
>
> Yes, that would be helpful, if only to prevent people from forking django-auth-ldap to add support for Python 3.
>
> The docs should just say "Since python-ldap doesn't support Python 3, you'll have to use an unofficial fork such as https://github.com/rbarrois/python-ldap/tree/py3". I'm working with Raphaël to get my patches merged there and drop my fork.
>
> Thank you,
>
> --
> Aymeric.
>
signature.asc

Aymeric AUGUSTIN

unread,
Apr 1, 2014, 5:48:33 AM4/1/14
to django-a...@googlegroups.com
Hi Peter,

Thanks for the merge!

Regarding mockldap, I’m still working with Raphaël Barrois to drop my fork of python-ldap (https://github.com/rbarrois/python-ldap/pull/1). Once this is settled, I’ll submit a pull request to point tox.ini to his version. Then it’ll need some docs about supported Python versions and it should be ready for release.

Regarding django-auth-ldap, I wanted to look at your fixes but I couldn’t find them. Did you push them to BitBucket? The issue with cidict might be a bug in the py3 branch of python-ldap.

Thank you,

--
Aymeric.

Peter Sagerson

unread,
Apr 1, 2014, 12:13:18 PM4/1/14
to django-a...@googlegroups.com
Oops, missed a step. Should all be up there now.
signature.asc

aymeric....@oscaro.com

unread,
Apr 11, 2014, 10:08:07 AM4/11/14
to django-a...@googlegroups.com
FYI Peter pushed yesterday to PyPI a version of django-auth-ldap that supports Python 3.

--
Aymeric.

Peter Sagerson

unread,
Apr 11, 2014, 4:36:49 PM4/11/14
to django-a...@googlegroups.com
Thanks for making that happen!
signature.asc
Message has been deleted

Peter Sagerson

unread,
Apr 25, 2014, 11:25:49 AM4/25/14
to django-a...@googlegroups.com
It's there:

https://pypi.python.org/pypi/django-auth-ldap/1.2.0


On Apr 25, 2014, at 4:02 AM, Ярослав Викторчик <ugz...@gmail.com> wrote:

> Is it still there? I can't install django-auth-ldap with pip.
>
> пятница, 11 апреля 2014 г., 14:08:07 UTC пользователь aymeric....@oscaro.com написал:
> FYI Peter pushed yesterday to PyPI a version of django-auth-ldap that supports Python 3.
>
> --
> Aymeric.
>
signature.asc

Matúš Honěk

unread,
Aug 29, 2014, 2:11:21 PM8/29/14
to django-a...@googlegroups.com
Hi, what is the status? 
When trying to install using pip3 (python3 version of pip), it still requires python-ldap (python2 version), which of course crashes. Even though the version of the django-auth-ldap is 1.2.0.
Any suggestions? Thanks.

Peter Sagerson

unread,
Aug 29, 2014, 7:05:32 PM8/29/14
to django-a...@googlegroups.com
Try installing the unofficial python-ldap port first:

$ pip3 install git+https://github.com/rbarrois/python-ldap.git@py3
$ pip3 install django-auth-ldap
signature.asc

Di majo

unread,
May 12, 2024, 1:40:43 PM5/12/24
to django-auth-ldap
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages