Softlayer getAllBillingItems stopped working?

2019-09-14 20:43发布

The following python script worked like a charm last month:

Script:

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

Today's result:

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

Other api actions work fine... any thoughts?

1条回答
Rolldiameter
2楼-- · 2019-09-14 21:18

well the charm has a defect and it is when the response has a big amount of data, that causes timeouts in the response and the conection is closed.

but this issue can be easily solved by using result limits take a look to this example:

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)

Regards

查看更多
登录 后发表回答