I am using vsphere-automation-sdk-python 8.0 in centos 7 with python version 3.7 Question 1: Does this python SDK work on vspehere or vcenter or ESXI? As I have provided the ESXI ip to the below...
See more...
I am using vsphere-automation-sdk-python 8.0 in centos 7 with python version 3.7 Question 1: Does this python SDK work on vspehere or vcenter or ESXI? As I have provided the ESXI ip to the below script to list down the vms facing issue. [root@v ~]# pip list Package Version ---------------------------------- --------- certifi 2022.12.7 cffi 1.15.1 charset-normalizer 2.0.12 cryptography 36.0.0 idna 3.4 lxml 4.9.2 nsx-policy-python-sdk 4.0.1.0.0 nsx-python-sdk 4.0.1.0.0 nsx-vmc-aws-integration-python-sdk 4.0.1.0.0 nsx-vmc-policy-python-sdk 4.0.1.0.0 pip 22.3.1 pycparser 2.21 pyOpenSSL 22.0.0 pyvmomi 7.0.3 requests 2.27.1 setuptools 62.0.0 six 1.16.0 urllib3 1.26.14 vapi-client-bindings 4.0.0 vapi-common-client 2.37.0 vapi-runtime 2.37.0 vmc-client-bindings 1.61.0 vmc-draas-client-bindings 1.20.0 vSphere-Automation-SDK 1.80.0 [root@v~]# cat /etc/centos-release RecoveryOS release 7.9.2009 (Core) [root@v~]# Tried to list vm using SDK sample code, which is not working. # cat tt.py
import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
session = requests.session()
print(session)
# Disable cert verification for demo purpose.
# This is not recommended in a production environment.
session.verify = False
# Disable the secure connection warning for demo purpose.
# This is not recommended in a production environment.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Connect to a vCenter Server using username and password
vsphere_client = create_vsphere_client(server='<ESXi server ip>', username='xxxx', password='xxxxx', session=session)
# List all VMs inside the vCenter Server
vsphere_client.vcenter.VM.list() Traceback (most recent call last): File "/root/tt.py", line 16, in <module> vsphere_client = create_vsphere_client(server='x.x.x.x', username='xxxx', password='xxxxx', session=session) File "/usr/local/lib/python3.9/site-packages/vmware/vapi/vsphere/client.py", line 173, in create_vsphere_client return VsphereClient(session=session, server=server, username=username, File "/usr/local/lib/python3.9/site-packages/vmware/vapi/vsphere/client.py", line 116, in __init__ session_id = session_svc.create() File "/usr/local/lib/python3.9/site-packages/com/vmware/cis_client.py", line 201, in create return self._invoke('create', None) File "/usr/local/lib/python3.9/site-packages/vmware/vapi/bindings/stub.py", line 345, in _invoke return self._api_interface.native_invoke(ctx, _method_name, kwargs) File "/usr/local/lib/python3.9/site-packages/vmware/vapi/bindings/stub.py", line 266, in native_invoke method_result = self.invoke(ctx, method_id, data_val) File "/usr/local/lib/python3.9/site-packages/vmware/vapi/bindings/stub.py", line 199, in invoke return self._api_provider.invoke(self._iface_id.get_name(), File "/usr/local/lib/python3.9/site-packages/vmware/vapi/security/client/security_context_filter.py", line 101, in invoke method_result = ApiProviderFilter.invoke( File "/usr/local/lib/python3.9/site-packages/vmware/vapi/provider/filter.py", line 75, in invoke method_result = self.next_provider.invoke( File "/usr/local/lib/python3.9/site-packages/vmware/vapi/protocol/client/msg/json_connector.py", line 79, in invoke response = self._do_request(VAPI_INVOKE, ctx, params) File "/usr/local/lib/python3.9/site-packages/vmware/vapi/protocol/client/msg/json_connector.py", line 127, in _do_request http_response.data.raise_for_status() File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 960, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://x.x.x.x/api Anyone one has any suggestion to resolve above issue.