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

ModuleNotFoundError: No module named 'cgi' #3348

Open
CharlesWiltgen opened this issue Nov 16, 2024 · 1 comment
Open

ModuleNotFoundError: No module named 'cgi' #3348

CharlesWiltgen opened this issue Nov 16, 2024 · 1 comment

Comments

@CharlesWiltgen
Copy link

CharlesWiltgen commented Nov 16, 2024

Description

The application fails to start when using Python 3.11 or later due to the removal of the cgi module. The error occurs when running Headphones.py.

Steps to Reproduce

  1. Clone the repository
  2. Navigate to the project directory
  3. Run the script with Python 3.11 or later
  4. Observe the error

Observed Error

Traceback (most recent call last):
  File "/Applications/Headphones/Headphones.py", line 27, in <module>
    from headphones import webstart, logger
  File "/Applications/Headphones/headphones/__init__.py", line 27, in <module>
    import cherrypy
  File "/Applications/Headphones/lib/cherrypy/__init__.py", line 68, in <module>
    from ._cperror import (
    ...<2 lines>...
    )
  File "/Applications/Headphones/lib/cherrypy/_cperror.py", line 135, in <module>
    from cherrypy.lib import httputil as _httputil
  File "/Applications/Headphones/lib/cherrypy/lib/httputil.py", line 15, in <module>
    from cgi import parse_header
ModuleNotFoundError: No module named 'cgi'

Environment

  • OS: macOS Sequoia 15.1
  • Python version: 3.11 or later
  • Headphones version: Latest from master branch

Possible Cause

The cgi module was removed in Python 3.11, causing the script to fail when importing parse_header.

Proposed Solutions

  1. Update the codebase to replace from cgi import parse_header with the equivalent implementation using the email module:
    from email.message import Message
    from email.parser import BytesParser
    
    def parse_header(value):
        parser = BytesParser()
        msg = parser.parsebytes(b"Content-Type: " + value.encode("ascii"))
        return msg.get_content_type(), msg.get_params()
  2. Document Python version requirements in the README.md and explicitly state support for Python versions prior to 3.11.
  3. Explore compatibility fixes for the broader application to support newer Python versions.

Additional Context

Switching to Python 3.10 resolves the issue temporarily, but long-term compatibility with Python 3.11+ would enhance the user experience.

Thank you! ✌️

AdeHub added a commit that referenced this issue Dec 7, 2024
@AdeHub
Copy link
Collaborator

AdeHub commented Dec 7, 2024

Can you try the develop branch

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

2 participants