pysaml2 icon indicating copy to clipboard operation
pysaml2 copied to clipboard

Using attribute_map_dir files throw error 'No module named __init__'

Open bumblebeexx opened this issue 1 year ago • 1 comments

In my SAML config I have put "attribute_map_dir": SAML_DIR / "attribute-maps",

This attribute-maps directory contains two files __init__.py and test.py

However, it causes this exception below.

Exception Type: ModuleNotFoundError at /saml2/login/
Exception Value: No module named '__init__'
...
...
File "djangosaml2/.venv/lib/python3.10/site-packages/saml2/config.py", line 338, in load
    self.load_complex(cnf)
  File "djangosaml2/.venv/lib/python3.10/site-packages/saml2/config.py", line 266, in load_complex
    acs = ac_factory(cnf.get("attribute_map_dir"))
  File "djangosaml2/.venv/lib/python3.10/site-packages/saml2/attribute_converter.py", line 67, in ac_factory
    mod = import_module(fil[:-3])

I removed __init__.py but then it threw error for test.py. It's happening because the function ac_factory() in saml2/attribute_converter.py has this code which is trying to import Python files - https://github.com/IdentityPython/pysaml2/blob/3daa066703f5ec433aeb9714a847330c540fc5d4/src/saml2/attribute_converter.py#L66

I also tried to print sys.path and it contains the full path to the map dir as set in the attribute_map_dir in config. https://github.com/IdentityPython/pysaml2/blob/3daa066703f5ec433aeb9714a847330c540fc5d4/src/saml2/attribute_converter.py#L63

I can't figure out how to get it working. Please advise the correct way to setup attribute maps.

bumblebeexx avatar Mar 06 '24 11:03 bumblebeexx

The issue here is that PySAML2 does not work with pathlib.Path instances, but rather expects paths to be string.

This should work in your case: "attribute_map_dir": os.path.join(SAML_DIR, "attribute-maps")

dino8890 avatar May 11 '25 08:05 dino8890