软层API timeou

2024-06-25 07:17:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Softlayer PythonAPI来获取硬件细节。脚本中途退出,出现以下API错误。我已经将服务器的数量限制在10台以下,但仍然存在错误。在

有没有办法可以关闭/断开与api的连接? 例如,如何在下面显式关闭“客户机”? 有什么可以克服的吗?在

client = SoftLayer.Client(username=USER, api_key=API_KEY,timeout = 1000)

hardware = client['Account'].getHardware(mask='id, fullyQualifiedDomainName,operatingSystem.softwareLicense.softwareDescription.longDescription,hardwareChassis.manufacturer,hardwareChassis.name,hardwareChassis.version,networkComponents.primaryIpAddress,processorCount,datacenter.name,primaryBackendIpAddress,motherboard.hardwareComponentModel.longDescription,processors.hardwareComponentModel.longDescription,memory.hardwareComponentModel.longDescription,memory.hardwareComponentModel.capacity,raidControllers.hardwareComponentModel.longDescription,hardDrives.hardwareComponentModel.longDescription',limit=limit,offset=offset);


File "/usr/local/bin/inv.py", line 90, in fetch_hw
hardware = client['Account'].getHardware(mask='id, fullyQualifiedDomainName,operatingSystem.softwareLicense.softwareDescription.longDescription,hardwareChassis.manufacturer,hardwareChassis.name,hardwareChassis.version,networkComponents.primaryIpAddress,processorCount,datacenter.name,primaryBackendIpAddress,motherboard,processors,memory,raidControllers,hardDrives',limit=limit,offset=offset);
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 392, in call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 360, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 263, in call
return self.transport(request)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/transports.py", line 199, in __call__
raise exceptions.TransportError(0, str(ex))
SoftLayer.exceptions.TransportError: TransportError(0): ("Connection broken: error(104, 'Connection reset by peer')", error(104, 'Connection reset by peer'))

Tags: nameinpyclientapiusrlocalline
1条回答
网友
1楼 · 发布于 2024-06-25 07:17:19

当进程正在运行时,无法关闭/断开客户端。在

我能够用超过150个硬件项目重现错误,而不是更少。有时需要更多的时间来获取所有的数据,因为你的面具很长,我建议你尽量减少它。在

互联网连接可能会影响到你的结果,我建议你重新审视一下。在

如果你想得到所有的BMS,你可以试着一部分一部分地得到所有的BMS,下面你可以看到一个例子。 如果错误仍然存在,您可以尝试逐个检索它们(限制=1)

"""
List Bare Metal servers.

The script retrieve all bare metal servers part by part in order to avoid time out
errors.

Important manual pages:
https://sldn.softlayer.com/reference/services/SoftLayer_Account
https://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
https://sldn.softlayer.com/reference/datatype/SoftLayer_Hardware/
https://sldn.softlayer.com/article/object-masks
https://sldn.softlayer.com/article/object-filters

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

# Your SoftLayer API username and key.
USERNAME = 'set-me'
API_KEY = 'set-me'

# The limit and offset of resultLimit feature.
limit = 10
offset = 0

# The array where all SoftLayer_Hardware objects will be stored.
hardware = []

# Flag to know if there are still SoftLayer_Hardware
has_items = True

# Create client instance
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)

object_mask = 'id,fullyQualifiedDomainName,operatingSystem.softwareLicense' \
              '.softwareDescription.longDescription,hardwareChassis.manufacturer,' \
              'hardwareChassis.name,hardwareChassis.version,networkComponents' \
              '.primaryIpAddress,processorCount,datacenter.name,' \
              'primaryBackendIpAddress,motherboard.hardwareComponentModel' \
              '.longDescription,processors.hardwareComponentModel.longDescription,' \
              'memory.hardwareComponentModel.longDescription,' \
              'memory.hardwareComponentModel.capacity,raidControllers' \
              '.hardwareComponentModel.longDescription,hardDrives' \
              '.hardwareComponentModel.longDescription'

try:
    """
    Following loop helps to retrieve all data part by part. This example shows how
    to retrieve each 10 objects. Just change limit value if you want to
    increase or decrease the number of retrieved data.
    """
    while has_items:
        hardware_items = client['SoftLayer_Account'].getHardware(mask=object_mask,
                                                                 limit=limit,
                                                                 offset=offset)
        hardware.extend(hardware_items)

        if len(hardware_items) > 0:
            offset += limit
        else:
            has_items = False

    print(hardware)

except SoftLayer.SoftLayerAPIError as e:
    """
    If there was an error returned from the SoftLayer API then bomb out with
    the error message.
    """
    print("Unable to get SoftLayer_Hardware objects: %s, %s " % (e.faultCode,
                                                                 e.faultString))

我希望这对你有帮助。在

敬上。在

相关问题 更多 >