2015-09-11 59 views
0

我正在嘗試使用QueryXML和SUDS來查詢Autotask。但是,由於縮進錯誤,我無法使用QueryXML。這是我的代碼:將QueryXML與SUDS和Python結合使用

class ConnectATWS(): 
    def __init__(self): 
     #Connect to server with the credentials 
     app_config = Init() 
     self.username = app_config.data["Username"] 
     self.password = app_config.data["Password"] 
     self.login_id = app_config.data["LoginID"] 
     self.url = app_config.data["AutotaskUpdateTicketEstimatedHours_net_autotask_webservices5_ATWS"] 
     strCurrentID = "0" 
     strCriteria = "<condition><field>Status<expression op=""NotEqual"">5</expression></field></condition>" 
     strQuery = "<queryxml><entity>Ticket</entity><query>" & _ 
         "<condition><field>id<expression op=""greaterthan"">" & strCurrentID & "</expression></field></condition>" & strCriteria & _ 
         "<condition><field>EstimatedHours<expression op=""isnull""></expression></field></condition>" & _ 
         "</query></queryxml>" 

     client = Client(self.url + "?WSDL", username=self.login_id, password=self.password) 
     response = client.service.query(strQuery) 
     print response 

這是我的錯誤:

File "/Users/AAAA/Documents/Aptana/AutotaskUpdateTicketEstimatedHours/Main.py", line 35 
    "<condition><field>id<expression op=""greaterthan"">" & strCurrentID & "</expression></field></condition>" & strCriteria & _ 
    ^
IndentationError: unexpected indent 

我怎樣才能繞過縮進錯誤和運行查詢?

+0

您可以粘貼錯誤的整個堆棧跟蹤嗎?你想用「&」和「_」操作符做什麼? – georgeofallages

回答

0

您不能連接字符串與&字符,請嘗試+。您還需要使用「\」來處理這些換行符:

strQuery = "<queryxml><entity>Ticket</entity><query>" + \ 
         "<condition><field>id<expression op=""greaterthan"">" + strCurrentID + "</expression></field></condition>" + strCriteria + \ 
         "<condition><field>EstimatedHours<expression op=""isnull""></expression></field></condition>" + \ 
         "</query></queryxml>" 
+0

謝謝,現在我必須指出我們如何正確使用帶有SUDS的AutotaskAPI的QueryXML .. – feners

相關問題