daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pyVim import connect
  2.     def connect_to_server(self, server=None, user=None, pwd=None, port=None):
  3.     if server is None:
  4.         server = _config_values("general", "host")
  5.     if user is None:
  6.         user = _config_values("general", "username")
  7.     if pwd is None:
  8.         pwd = _config_values("general", "password")
  9.     if port is None:
  10.         port = _config_values("general", "port")
  11.     self._server = server
  12.     self._user = user
  13.     self._password = pwd
  14.     self._port = int(port)
  15.     try:
  16.         service_instance = connect.SmartConnect("http", self._server,  self._port, self._user, self._password)
  17.     except ConfigParseError:
  18.         pass
  19.    
  20. import urllib3.contrib.pyopenssl
  21.     urllib3.contrib.pyopenssl.inject_into_urllib3()
  22.    
  23. <pre><code>    
  24. Traceback (most recent call last):
  25. File "D:python_learningvmwareATFtestVmwareatf.py", line 15, in <module>
  26. main()
  27. File "D:python_learningvmwareATFtestVmwareatf.py", line 12, in main
  28. obj.connect_to_server()
  29. File "D:python_learningvmwareATFvmwareatfvmware.py", line 52,in      connect_to_server
  30. service_instance = connect.SmartConnect( host=self._server,    port=self._port,  user=self._user, pwd=self._password)
  31. File "C:Python27libsite-packagespyVimconnect.py", line 577, in SmartConnect  preferredApiVersions)
  32. File "C:Python27libsite-packagespyVimconnect.py", line 520, in  __FindSupportedVersion    path)
  33. File "C:Python27libsite-packagespyVimconnect.py", line 435, in __GetServiceVersionDescription
  34. sock = requests.get(url, verify=False)
  35. File "C:Python27libsite-packagesrequestsapi.py", line 69, in get
  36. return request('get', url, params=params, **kwargs)
  37. File "C:Python27libsite-packagesrequestsapi.py", line 50, in request
  38. response = session.request(method=method, url=url, **kwargs)
  39. File "C:Python27libsite-packagesrequestssessions.py", line 465, in  request
  40. resp = self.send(prep, **send_kwargs)
  41. File "C:Python27libsite-packagesrequestssessions.py", line 573, in send
  42. r = adapter.send(request, **kwargs)
  43. File "C:Python27libsite-packagesrequestsadapters.py", line 431, in send
  44. raise SSLError(e, request=request)
  45. requests.exceptions.SSLError: [Errno bad handshake] (-1, 'Unexpected EOF')
  46. </code></pre>
  47.    
  48. sslContext = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
  49. sslContext.verify_mode = ssl.CERT_NONE
  50. si = SmartConnect(host=host,user=username,pwd=password,sslContext=sslContext)
  51.    
  52. ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed...
  53.    
  54. import requests
  55. requests.packages.urllib3.disable_warnings()
  56.  
  57. import ssl
  58.  
  59. try:
  60.     _create_unverified_https_context = ssl._create_unverified_context
  61. except AttributeError:
  62.     # Legacy Python that doesn't verify HTTPS certificates by default
  63.     pass
  64. else:
  65.      # Handle target environment that doesn't support HTTPS verification
  66.     ssl._create_default_https_context = _create_unverified_https_context
  67.    
  68. sslContext = ssl.create_default_context()
  69. sslContext.check_hostname = False
  70. sslContext.verify_mode = ssl.CERT_NONE
  71. si = SmartConnect(host=host,user=username,pwd=password,sslContext=sslContext)
  72.    
  73. #!/usr/bin/env python3.6
  74. # encoding: utf-8
  75.  
  76. from pyVim import connect
  77. import ssl
  78.  
  79.  
  80. def login():
  81.     ssl_context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
  82.     ssl_context.verify_mode = ssl.CERT_NONE
  83.     si = connect.SmartConnect(host='sclautoesxd12.engba.veritas.com', user='root', pwd='P@ssw0rd',
  84.                               sslContext=ssl_context)
  85.     print(si)
  86.     print('nHello World!n')
  87.     print('If you got here, you authenticted into vCenter.')
  88.  
  89.  
  90. if __name__ == '__main__':
  91.     login()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top