title: How to use Types and Methods with SUDS
body: <p>My code connects to a Autotask service through SUDS. I get a list of Methods, one of which I have to call. I'm new to this, so I'm not sure on how to correctly do this. This is my code, including help by Bodsda:</p>
  
  <pre><code>import os, sys
  import xml.etree.ElementTree as ET
  from suds.client import Client
  from suds.sax.element import Element
  
  
  class Init():
      def __init__(self):
          #Search the app.config file for all data to be used
          script_dir = os.path.dirname(__file__)
          file_path = "app.config"
          abs_file_path = os.path.join(script_dir, file_path) 
  
          tree = ET.parse(abs_file_path)
          root = tree.getroot()
          sites = root.iter('AutotaskUpdateTicketEstimatedHours.My.MySettings')
          self.data = {}
          for site in sites: 
              apps = site.findall('setting')
              for app in apps:
                  self.data[app.get('name')] = app.find('value').text
  
  
  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"]
          strQuery = """
          &lt;queryxml&gt;
              &lt;entity&gt;Ticket&lt;/entity&gt;
              &lt;query&gt;
                  &lt;condition&gt;
                      &lt;field&gt;Id
                          &lt;expression op="GreaterThan"&gt;0&lt;/expression&gt;
                      &lt;/field&gt;
                  &lt;/condition&gt;
                  &lt;condition&gt;
                      &lt;field&gt;Status
                          &lt;expression op="NotEqual"&gt;5&lt;/expression&gt;
                      &lt;/field&gt;
                  &lt;/condition&gt;
                  &lt;condition&gt;
                      &lt;field&gt;EstimatedHours
                          &lt;expression op="IsNull"&gt;&lt;/expression&gt;
                      &lt;/field&gt;
                  &lt;/condition&gt;
              &lt;/query&gt;
          &lt;/queryxml&gt;"""
          new_url = 'https://webservices5.autotask.net/atservices/1.5/atws.wsdl'
          client = Client(new_url, username=self.login_id, password=self.password)
          response = client.service.query(strQuery)
  
          if response.ReturnCode != 1:
              print "Error code: %s" % response.ReturnCode
              print "Error response: %s" % response.Errors
              sys.exit(1)
          else:
              print "Query successful..."
              print "============================="
              print response.EntityResults
  
  
  
  if __name__ == '__main__':
      handler = ConnectATWS()
  </code></pre>
  
  <p>This is my response: </p>
  
  <pre><code>(ATWSResponse){
     ReturnCode = 1
     EntityResults = ""
     EntityResultType = "ticket"
     Errors = ""
     EntityReturnInfoResults = ""
   }
  </code></pre>
  
  <p>This is the list of Methods and Types I get through the client:</p>
  
  <pre><code>    Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913
  
  Service ( ATWS ) tns="http://autotask.net/ATWS/v1_5/"
     Prefixes (1)
        ns0 = "http://autotask.net/ATWS/v1_5/"
     Ports (1):
        (ATWSSoap)
           Methods (14):
              CreateAttachment(Attachment attachment, )
              DeleteAttachment(xs:long attachmentId, )
              GetAttachment(xs:long attachmentId, )
              GetFieldInfo(xs:string psObjectType, )
              GetInvoiceMarkup(xs:int InvoiceId, xs:string Format, )
              GetWsdlVersion()
              create(ArrayOfEntity Entities, )
              delete(ArrayOfEntity Entities, )
              getEntityInfo()
              getThresholdAndUsageInfo()
              getUDFInfo(xs:string psTable, )
              getZoneInfo(xs:string UserName, )
              query(xs:string sXML, )
              update(ArrayOfEntity Entities, )
           Types (108):
              ATWSError
              ATWSResponse
              ATWSZoneInfo
              Account
              AccountLocation
              AccountNote
              AccountTeam
              AccountToDo
              ActionType
              AdditionalInvoiceFieldValue
              AllocationCode
              Appointment
              ArrayOfATWSError
              ArrayOfEntity
              ArrayOfEntityInfo
              ArrayOfEntityReturnInfo
              ArrayOfField
              ArrayOfPickListValue
              ArrayOfUserDefinedField
              Attachment
              AttachmentInfo
              AutotaskIntegrations
              BillingItem
              BillingItemApprovalLevel
              ChangeRequestLink
              ClientPortalUser
              Contact
              Contract
              ContractBlock
              ContractCost
              ContractFactor
              ContractMilestone
              ContractNote
              ContractRate
              ContractRetainer
              ContractService
              ContractServiceAdjustment
              ContractServiceBundle
              ContractServiceBundleAdjustment
              ContractServiceBundleUnit
              ContractServiceUnit
              ContractTicketPurchase
              Country
              Department
              Entity
              EntityDuplicateStatus
              EntityInfo
              EntityReturnInfo
              EntityReturnInfoDatabaseAction
              ExpenseItem
              ExpenseReport
              Field
              InstalledProduct
              InstalledProductType
              InstalledProductTypeUdfAssociation
              InternalLocation
              InventoryItem
              InventoryItemSerialNumber
              InventoryLocation
              InventoryTransfer
              Invoice
              InvoiceTemplate
              Opportunity
              PaymentTerm
              Phase
              PickListValue
              Product
              ProductVendor
              Project
              ProjectCost
              ProjectNote
              PurchaseOrder
              PurchaseOrderItem
              PurchaseOrderReceive
              Quote
              QuoteItem
              QuoteLocation
              Resource
              ResourceRole
              ResourceSkill
              Role
              SalesOrder
              Service
              ServiceBundle
              ServiceBundleService
              ServiceCall
              ServiceCallTask
              ServiceCallTaskResource
              ServiceCallTicket
              ServiceCallTicketResource
              ShippingType
              Skill
              Task
              TaskNote
              TaskPredecessor
              TaskSecondaryResource
              Tax
              TaxCategory
              TaxRegion
              Ticket
              TicketChangeRequestApproval
              TicketCost
              TicketNote
              TicketSecondaryResource
              TimeEntry
              UserDefinedField
              UserDefinedFieldDefinition
              UserDefinedFieldListItem
  </code></pre>
  
  <p>I need to use the ATWSResponse type but I don't really understand how to do this. Furthermore, I'm attempting to simulate this vb.net code part which does what I'm trying to do in Python:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub ProcessTicket()
      Dim boolQueryFinished = False
      Dim strCurrentID As String = "0"
      Dim strQuery As String
      Dim strCriteria As String = ""
      Dim TicketArray(0) As Ticket
  
      While (Not (boolQueryFinished))
          If LCase(Trim(varIgnoreTicketStatus)) = "true" Then
              WriteToLog("Updating All Tickets Where EstimatedHours Is Null")
          Else
              WriteToLog("Updating Ticket Where Status &lt;&gt; Complete And EstimatedHours Is Null")
              ' 5 - Complete
              strCriteria = "&lt;condition&gt;&lt;field&gt;Status&lt;expression op=""NotEqual""&gt;5&lt;/expression&gt;&lt;/field&gt;&lt;/condition&gt;"
          End If
  
          strQuery = "&lt;queryxml&gt;&lt;entity&gt;Ticket&lt;/entity&gt;&lt;query&gt;" &amp; _
                      "&lt;condition&gt;&lt;field&gt;id&lt;expression op=""greaterthan""&gt;" &amp; strCurrentID &amp; "&lt;/expression&gt;&lt;/field&gt;&lt;/condition&gt;" &amp; strCriteria &amp; _
                      "&lt;condition&gt;&lt;field&gt;EstimatedHours&lt;expression op=""isnull""&gt;&lt;/expression&gt;&lt;/field&gt;&lt;/condition&gt;" &amp; _
                      "&lt;/query&gt;&lt;/queryxml&gt;"
  
          Dim r As ATWSResponse
          Dim strLog As String
  
          r = ATWSService.query(strQuery)
          WriteToLog("Found " &amp; r.EntityResults.Length &amp; " Tickets begining at " &amp; strCurrentID)
  
          If r.EntityResults.Length &gt; 0 Then
              For Each ent As Entity In r.EntityResults
                  CType(ent, Ticket).EstimatedHours = EstHoursDefault
  
                  TicketArray(0) = CType(ent, Ticket)
  
                  Dim sResponse As ATWSResponse
                  Dim entityArray() As Entity = CType(TicketArray, Entity())
                  sResponse = ATWSService.update(entityArray)
  </code></pre>
  
  <p>My question is how can I successfully query with the QueryXML with my Python code and return entities like in the vb.net code?</p>