0

我正在尝试使用 lib cloud 连接到 Vcloud,使用 firefox 的 rest API 进行身份验证工作正常,但在 python 中失败。我错过了什么吗?

__author__ = 'kshk'
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

import libcloud.security



def testConnection():
    #libcloud.security.VERIFY_SSL_CERT = False
    vcloud = get_driver(Provider.VCLOUD)
    driver = vcloud("login", "passwd", host = "https://portal.vcloud")

    nodes = driver.list_nodes()
    print nodes

def main():
    testConnection()

if __name__ == "__main__":
    main()

输出:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py
Traceback (most recent call last):
  File "/Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py", line 21, in <module>
    main()
  File "/Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py", line 18, in main
    testConnection()
  File "/Users/krishnaa/PycharmProjects/VCloud-API/vcloud_test.py", line 14, in testConnection
    nodes = driver.list_nodes()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 559, in list_nodes
    return self.ex_list_nodes()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 573, in ex_list_nodes
    vdcs = self.vdcs
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 407, in vdcs
    self.connection.check_org()  # make sure the org is set.
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 325, in check_org
    self._get_auth_token()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/compute/drivers/vcloud.py", line 835, in _get_auth_token
    headers=self._get_auth_headers())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 973, in request
    self._send_request(method, url, body, headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1007, in _send_request
    self.endheaders(body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 829, in _send_output
    self.send(msg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 791, in send
    self.connect()
  File "/Library/Python/2.7/site-packages/apache_libcloud-0.15.1-py2.7.egg/libcloud/httplib_ssl.py", line 96, in connect
    self.timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
4

1 回答 1

2

您的代码不起作用,因为“主机”参数只需要主机名而不是 url。

如果您将其更改为:

driver = vcloud("login", "passwd", host="portal.vcloud")

它应该工作。

于 2014-08-02T15:45:09.403 回答