簡體   English   中英

結合使用QueryXML和SUDS和Python

[英]Using QueryXML with SUDS and Python

我正在嘗試使用帶有SUDS的QueryXML來查詢自動任務。 但是,由於縮進錯誤,我無法使用QueryXML。 這是我的代碼:

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

如何繞過縮進錯誤並運行查詢?

您不能將字符串與&字符連接在一起,而是嘗試+。 另外,您需要使用“ \\”來處理這些換行符:

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>"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM