SAML-Toolkits/python-saml

using onelogin/saml2/lxml.py triggers ImportError: cannot import name etree. Simple fix is described below.

hsalis opened this issue · 1 comments

A naive install of python-saml triggered an Import Error:

File "/usr/local/lib/python2.7/dist-packages/onelogin/saml2/utils.py", line 18, in <module>
    from lxml import etree
ImportError: cannot import name etree

I read that python-saml was compatible with lxml up to version 4.7.1. So I uninstalled lxml and re-installed lxml==4.6.5. But the same ImportError was triggered.

After some investigation, I found that python-saml carries its own copy of lxml.py in its distribution located at onelogin/saml2/lxml.py. Unfortunately, it looks like this lxml.py is incompatible with python-saml (>4.7.1).

The simple fix is to remove onelogin/saml2/lxml.py and onelogin/saml2/lxml.pyc from the distribution. Python will then find the installed lxml.py on the PythonPath. When the lxml.py is version 4.6.5, then the imports work.

Recommend removal of onelogin/saml2/lxml.py and onelogin/saml2/lxml.pyc.

Thanks! :)

There is no such onelogin/saml2/lxml.py file

python-saml 2.1.1 fixed the version dependence of lxml to be lower than 4.7.0 because such version had a bug.

I plan to make a nee release to remove such restriction