How to connect to a vm using python (SyntaxError: multiple exception types must be parenthesized)

How to connect to a vm using python (SyntaxError: multiple exception types must be parenthesized)

我正在尝试使用 python 连接到虚拟机。我需要做一个服务器健康检查报告

我已经编写了以下代码来连接到虚拟机,但出现错误

svr = "test8ap"
import winrm
import getpass
from pysphere.vi_server import VIServer
try:
    usrname = input("Enter Username: ")
    passwd = getpass.getpass('Enter Password: ')
except Exception as err:
   print('Error Occured : ', err)

def viConnect(vCenter,username,password,vmname):
    server = pysphere.VIServer()
    server.connect(vCenter,username,password)
    return getVm(server,vmname)

conn = viConnect('12.68.18.1',usrname,passwd,svr)

错误

C:\Users\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/PycharmProjects/pythonProject/venv/VM_Data.py
Traceback (most recent call last):
  File "C:\Users\PycharmProjects\pythonProject\venv\VM_Data.py", line 4, in <module>
    from pysphere.vi_server import VIServer
  File "C:\Users\PycharmProjects\pythonProject\venv\lib\site-packages\pysphere\__init__.py", line 171, in <module>
    from pysphere.vi_task import VITask
  File "C:\Users\PycharmProjects\pythonProject\venv\lib\site-packages\pysphere\vi_task.py", line 110
    except (VI.ZSI.FaultException), e:
            ^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized

Process finished with exit code 1

你能告诉我这里的问题是什么吗?

提供了尝试过的解决方案

但仍然出现同样的错误

您正在使用的模块的代码中似乎存在错误。那是你的模块吗?如果不尝试重新安装它并检查天气它是否与您当前的 python 版本兼容!