Softlayer getAllBillingItems停止工作了吗?

时间:2017-02-01 09:37:03

标签: python ibm-cloud-infrastructure

以下python脚本上个月就像魅力一样:

脚本:

import SoftLayer
client = SoftLayer.Client(username='someUser', api_key='someKey')
LastInvoice = client['Account'].getAllBillingItems()
print LastInvoice

今天的结果:

C:\Python27\python.exe C:/Users/username/Documents/Python/Softlayer/Softlayer5.py
Traceback (most recent call last):
  File "C:/Users/username/Documents/Python/Softlayer/Softlayer5.py", line 8, in <module>
    LastInvoice = client['Account'].getAllBillingItems()
  File "C:\Python27\lib\site-packages\SoftLayer\API.py", line 392, in call_handler
    return self(name, *args, **kwargs)
  File "C:\Python27\lib\site-packages\SoftLayer\API.py", line 360, in call
    return self.client.call(self.name, name, *args, **kwargs)
  File "C:\Python27\lib\site-packages\SoftLayer\API.py", line 263, in call
    return self.transport(request)
  File "C:\Python27\lib\site-packages\SoftLayer\transports.py", line 197, in __call__
    raise exceptions.TransportError(ex.response.status_code, str(ex))
SoftLayer.exceptions.TransportError: TransportError(500): 500 Server Error: Internal Server Error for url: https://api.softlayer.com/xmlrpc/v3.1/SoftLayer_Account

其他api行为正常......有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好的魅力有缺陷,当响应有大量数据时,会导致响应超时并且连接被关闭。

但是使用结果限制可以轻松解决此问题,请查看此示例:

import SoftLayer

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

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)

offset = 0
limit = 50

accountService = client['SoftLayer_Account']

while True:
    try:
        result = accountService.getAllBillingItems(limit=limit, offset=offset)
        offset = offset + limit
        limit = limit + limit
        print(result)
        if not result:
            break
    except SoftLayer.SoftLayerAPIError as e:
        print("Unable to retrieve the servers . " % (e.faultCode, e.faultString))
        exit(1)

此致