Skip to content

Commit 0a0d5e1

Browse files
author
ddraganov
committed
Fix host and port values for proxy connections - closes #1095
1 parent 9a8956f commit 0a0d5e1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pyVmomi/SoapAdapter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@
9696

9797
COOKIE_NAME = "vmware_soap_session"
9898

99+
# Address gh-100985, fixed in Python 3.11.9 and 3.12.4
100+
def _gh100985(addr):
101+
if addr and addr[0] == '[' and addr[-1] == ']':
102+
return addr[1:-1]
103+
else:
104+
return addr
105+
99106
# MethodFault type
100107
MethodFault = GetVmodlType("vmodl.MethodFault")
101108
# Localized MethodFault type
@@ -1538,20 +1545,19 @@ def GetConnection(self):
15381545

15391546
# Python fails if both host:port pair
15401547
# and port are used for HTTPConnection
1541-
host = getattr(self, 'httpProxyHost', self.host.rsplit(":", 1)[0])
1542-
port = getattr(self, 'httpProxyPort', self.port)
1543-
1544-
# Fix for gh-100985 which is fixed
1545-
# in Python 3.11.9 and Python 3.12.4
1546-
if host and host[0] == '[' and host[-1] == ']':
1547-
host = host[1:-1]
1548+
host = self.host.rsplit(":", 1)[0]
1549+
port = self.port
1550+
conn_host = getattr(self, 'httpProxyHost', host)
1551+
conn_port = getattr(self, 'httpProxyPort', port)
1552+
conn_host = _gh100985(conn_host)
15481553

1549-
conn = self.scheme(host=host, port=port, **self.schemeArgs)
1554+
conn = self.scheme(host=conn_host, port=conn_port, **self.schemeArgs)
15501555
if self.is_tunnel:
15511556
if hasattr(self, 'sslProxyPath'):
15521557
conn.setVcTunnel(self.sslProxyPath)
15531558
elif hasattr(self, 'httpProxyHost'):
15541559
customHeaders = self._customHeaders if self._customHeaders else {}
1560+
host = _gh100985(host)
15551561
conn.set_tunnel(host, port, customHeaders)
15561562
_Connect(connection=conn, serverPemCert=self.serverPemCert, thumbprint=self.thumbprint)
15571563

0 commit comments

Comments
 (0)