vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.21k stars 764 forks source link

Connection to vCenter Server via authenticated proxy server fails #1022

Closed VedaNiks closed 1 year ago

VedaNiks commented 1 year ago

Is your feature request related to a problem? Please describe.

I need to connect to vCenter server via authenticated proxy. But, I could not do so using SmartConnect. I know, I need to send Proxy-Authorization header in the SmartConnect request but I couldn't find a way to do this. I tried putting it in customHeaders attribute as given below:

custom_headers = {"Proxy-Authorization": "Basic c3F1aWRfdXNlcjpwYXNzd29yZA=="} si = SmartConnect(host=vcenter_address, user='administrator@vsphere.local', pwd=password, sslContext=context, httpProxyHost=squid_proxy_server_address, httpProxyPort=port, customHeaders=custom_headers)

On executing above code I see below error:

Traceback (most recent call last):
  File "connect_to_vc.py", line 19, in <module>
    si = SmartConnect(host=vcenter_address
  File "/usr/local/lib/python3.8/dist-packages/pyVim/connect.py", line 939, in SmartConnect
    supportedVersion = __FindSupportedVersion(protocol, host, port, path,
  File "/usr/local/lib/python3.8/dist-packages/pyVim/connect.py", line 763, in __FindSupportedVersion
    serviceVersionDescription = __GetServiceVersionDescription(
  File "/usr/local/lib/python3.8/dist-packages/pyVim/connect.py", line 694, in __GetServiceVersionDescription
    return __GetElementTree(protocol, server, port,
  File "/usr/local/lib/python3.8/dist-packages/pyVim/connect.py", line 655, in __GetElementTree
    conn.request("GET", path)
  File "/usr/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/usr/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/usr/lib/python3.8/http/client.py", line 1418, in connect
    super().connect()
  File "/usr/lib/python3.8/http/client.py", line 927, in connect
    self._tunnel()
  File "/usr/lib/python3.8/http/client.py", line 905, in _tunnel
    raise OSError("Tunnel connection failed: %d %s" % (code,
OSError: Tunnel connection failed: 407 Proxy Authentication Required

Is authenticated proxy supported in pyvmomi? If not, can you please guide me how I can do this using pyvmomi?

Describe the solution you'd like

Add authenticated proxy support in pyvmomi.

Describe alternatives you've considered

None

Additional context

No response

VedaNiks commented 1 year ago

Hello, Can anyone tell me if there is a way to use authenticated proxy server with pyVmomi?