SyntaxError: multiple exception types must be parenthesized

Question:

I am a beginner and have a problem after installing pycaw for the audio control using python, on putting the basic initialization code for pycaw, i get the following error:-

Traceback (most recent call last):
  File "c:Users...volumeControl.py", line 7, in <module>
    from comtypes import CLSCTX_ALL
  File "C:...envlibsite-packagescomtypes__init__.py", line 375
    except COMError, err:
           ^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized

Basic initialization:-

from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume

devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
    IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))

I tried searching for this all over the web but could not find a fix
I also trying going into the module file inside the virtual env and parenthize by putting brackets around COMError, err
But same error with other lines in code came,
Also tried reinstalling pycaw and trying to install different versions of pycaw several times but nothing fixed

How to fix this error?

Asked By: Ayush

||

Answers:

After a time searching I found that comtypes uses a tool to be compatible with both python 2 and 3 and that is no longer works in new versions. I had to downgrade two packages and reinstall comtypes:

pip install setuptools==57.0.0 --force-reinstall
pip install wheel==0.36.2 --force-reinstall
pip uninstall comtypes
pip install --no-cache-dir comtypes
Answered By: Romulo Santos

I just figured out what the cryptic "SyntaxError: multiple exception types must be parenthesized" message means.
All it’s trying to tell you is that in the newer version of Python you’re using, this syntax is no longer valid:

except COMError, err:

instead, you should be using this syntax:

except COMError(err):
Answered By: B K
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.