简体   繁体   English

结合使用QueryXML和SUDS和Python

[英]Using QueryXML with SUDS and Python

I'm trying to use a QueryXML with SUDS to query Autotask. 我正在尝试使用带有SUDS的QueryXML来查询自动任务。 However I'm not able to use the QueryXML because of an indentation error. 但是,由于缩进错误,我无法使用QueryXML。 This is my code: 这是我的代码:

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

This is my error: 这是我的错误:

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

How can I bypass the indentation error and run the query? 如何绕过缩进错误并运行查询?

You can't concatenate the strings with the & character, try + instead. 您不能将字符串与&字符连接在一起,而是尝试+。 Also you need to use the "\\" to handle those line breaks: 另外,您需要使用“ \\”来处理这些换行符:

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