Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13 Compatibility #976

Open
ephes opened this issue Jan 19, 2025 · 0 comments
Open

Python 3.13 Compatibility #976

ephes opened this issue Jan 19, 2025 · 0 comments

Comments

@ephes
Copy link

ephes commented Jan 19, 2025

Hi there,

First off, thank you for this amazing library! I recently wrote a blog post demonstrating how to use Django as a service provider, with pysaml2 serving as an example IdP. A reader has since pointed out that it doesn’t work with Python 3.13, and after some investigation, I suspect the issue stems from the removal of the cgi module in Python 3.13.

I noticed that pysaml2 still imports cgi in a couple of places. For example:

In src/saml2/httputil.py:

# The `cgi` module is used here:
formdata = cgi.parse(environ["wsgi.input"], environ, empty, err)

# Since `parse_qs` is already imported, this could potentially be replaced with:
input_stream = environ["wsgi.input"]
content_length = int(environ.get("CONTENT_LENGTH", 0))
form_data_bytes = input_stream.read(content_length)
form_data = parse_qs(form_data_bytes.decode('utf-8'))

In src/saml2/pack.py and src/saml2/httputil.py:

# The fallback to `cgi` for HTML escaping could be removed, as the `html` module 
# (introduced in Python 3.4) provides the necessary functionality:
try:
    import html
except Exception:
    import cgi as html  # type: ignore[no-redef]

Would it make sense to update these references to make pysaml2 compatible with Python 3.13? I’d be happy to help test any changes.

Best regards,
Jochen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant