我正在尝试使用Python将虚拟访客添加到带宽池中。我的休息呼叫没有问题,但由于某种原因,我的python脚本失败了。这是我试过的2个脚本
import SoftLayer
from pprint import pprint as pp
import logging
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(3)
client = SoftLayer.Client()
parms = { "parameters": [[], [], [{ "id": "17437341" }], []]}
pool_id = '286469'
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(parms["parameters"], id=pool_id)
pp(addtopool)
和
import SoftLayer
from pprint import pprint as pp
import logging
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(3)
client = SoftLayer.Client()
parms = [[], [], [{'id': '17406051'}], []]
pool_id = '286469'
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(parms, id=pool_id)
pp(addtopool)
在这两种情况下,API都会返回
"POST /xmlrpc/v3.1/SoftLayer_Network_Bandwidth_Version1_Allotment HTTP/1.1" 200 251
=== RESPONSE ===
{'Content-Length': '251', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Server': 'Apache', 'Connection': 'close', 'ntCoent-Length': '443', 'Cache-Control': 'private', 'Date': 'Wed, 27 Apr 2016 18:10:07 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Type': 'text/xml'}
<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value>
<string>SoftLayer_Exception_Public</string>
</value>
</member>
<member>
<name>faultString</name>
<value>
<string>An error has occurred while processing your request. Please try again later.</string>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>
Traceback (most recent call last):
File "/Users/ryan/Projects/apitesting/python/addtopool.py", line 13, in <module>
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(parms,id=pool_id)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 373, in call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 341, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 237, in call
return self.transport(request)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/transports.py", line 187, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Public): An error has occurred while processing your request. Please try again later.
供参考,有效的卷曲请求是
curl --verbose --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -k -X POST -d '{"parameters": [[], [], [{ "id": "17812855" }], []]}' "https://api.softlayer.com/rest/v3/SoftLayer_Network_Bandwidth_Version1_Allotment/286469/requestVdrContentUpdates"
* Trying 66.228.119.120...
* Connected to api.softlayer.com (66.228.119.120) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: api.softlayer.com
* Server certificate: RapidSSL SHA256 CA - G3
* Server certificate: GeoTrust Global CA
* Server auth using Basic with user 'xxx'
> POST /rest/v3/SoftLayer_Network_Bandwidth_Version1_Allotment/286469/requestVdrContentUpdates HTTP/1.1
> Host: api.softlayer.com
> Authorization: Basic xxxx
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 52
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 52 out of 52 bytes
< HTTP/1.1 200 OK
< Date: Wed, 27 Apr 2016 18:12:40 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< Content-Length: 4
< Vary: Accept-Encoding
< Connection: close
< Content-Type: application/json
<
* Closing connection 0
true
答案 0 :(得分:0)
您不必将所有json作为参数传递给Softlayer python客户端,这是错误的,请参阅此示例
import SoftLayer
from pprint import pprint as pp
import logging
client = SoftLayer.Client()
hardwareToAdd = []
hardwareToRemove = []
cloudsToAdd = [{"id": 15535983 }]
pool_id = '234471'
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(hardwareToAdd, hardwareToRemove, cloudsToAdd, id=pool_id)
pp(addtopool)
此致