【问题标题】:Using QueryXML with SUDS and Python将 QueryXML 与 SUDS 和 Python 结合使用
【发布时间】:2015-09-11 23:33:46
【问题描述】:

我正在尝试使用带有 SUDS 的 QueryXML 来查询 Autotask。但是,由于缩进错误,我无法使用 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

如何绕过缩进错误并运行查询?

【问题讨论】:

  • 你能粘贴你得到的错误的整个堆栈跟踪吗?你想用“&”和“_”运算符做什么?

标签: python python-2.7 suds


【解决方案1】:

您不能将字符串与 & 字符连接,请尝试使用 + 代替。您还需要使用“\”来处理这些换行符:

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

【讨论】:

  • 谢谢,现在我必须弄清楚如何正确使用带有 SUDS 的 AutotaskAPI 的 QueryXML..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-05
  • 2018-02-19
  • 1970-01-01
  • 2011-12-27
  • 2021-09-23
  • 1970-01-01
  • 2011-04-15
相关资源
最近更新 更多