将QueryXML与SUDS和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>"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章