我有SoftLayer_Ticket一些問題:的SoftLayer API:如何創建一個機票和附加文件到票
SoftLayer_Ticket :: createStandardTicket
我被弄得參數:http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createStandardTicket。
這個API的一些參數(attachmentId,rootPassword ...)是可選的,但我找不到一種方法來忽略它們。 我認爲我可以使用「paramName = XXX」來指定我需要的參數,並且像這樣調用:
client['Ticket'].createStandardTicket(templateObject=templateObject,contents=contents, attachedFiles=attachedFiles)
但它失敗了。 ?如果我要附加一些文件,而不是一臺服務器,我應該怎麼稱呼此功能,請給我一個例子,謝謝〜
SoftLayer_Ticket :: addAttachedFile
我想這個API附加一些文件:
的test.txt(文本文件)和test.png(圖片)
我成功了附加的test.txt,但未能連接test.png。
代碼:
import SoftLayer
from SoftLayer import utils
class Ticket_Manager(object):
def __init__(self, client):
self.sl_account = client['Account']
self.sl_ticket = client['Ticket']
self.sl_ticket_subject = client['Ticket_Subject']
def test_attach_files(self, ticket_config):
if ticket_config.has_key('attachedFiles'):
for file in ticket_config['attachedFiles']:
print self.sl_ticket.addAttachedFile(file, id=27333259)
def test_create_ticket(self, ticket_config):
pass
if __name__ == '__main__':
client = SoftLayer.create_client_from_env(username=API_USERNAME,api_key=API_KEY)
ticket_mgt = Ticket_Manager(client)
ticket_contents = 'SoftLayer API(SoftLayer_Ticket) test, thanks!'
with open('test.txt', 'rb') as file1:
bytes_stream1 = file1.read()
file1.close()
with open('test.png', 'rb') as file2:
bytes_stream2 = file2.read()
file2.close()
ticket_config = {
'subjectId':1522,
'title':'SoftLayer API test(no need to reply)',
'contents':ticket_contents,
'serverId':0,
'serverRootPassword':'',
'accessPort':'',
'serverType':'virtual',
'type':'standard',
'attachedFiles':[
{
'filename':'test.txt',
'data':bytes_stream1
},
{
'filename':'test.png',
'data':bytes_stream2
}
],
'attachedAdditionalEmails':[
]
}
ticket_mgt.test_attach_files(ticket_config)
我在linux下運行此腳本,並會見了此異常:
SoftLayer.exceptions.SoftLayerAPIError:SoftLayerAPIError(SoftLayer_Ticket):未找到有效的認證頭。
謝謝您的回答!這對我有用。 我重新編輯了我的問題,並在那裏粘貼了我的源代碼。 我仍然陷在問題2中。 – ChrisM
ChrisM,請參閱關於您的問題2的答案(更新部分)。 –