CA Service Management

Expand all | Collapse all

Webservice - using doSelect method with python

Jump to Best Answer
  • 1.  Webservice - using doSelect method with python

    Posted 03-28-2018 11:46 AM

    Hello everybody, I'm trying to consume the WS method doSelect, in SOAPUI and I make this query

     

           <sid>sid</sid>
          <objectType>cr</objectType>
          <whereClause>open_date > 1519862400 AND open_date &lt; 1522368000
          </whereClause>
          <maxRows>-1</maxRows>
          <attributes>
          <!--1 or more repetitions:-->
         <string>ref_num</string>
        <string>open_date</string>
        </attributes>

    And it works perfectly, returns me what I want, but now is my problem, when I try to use that method in Python, I have this class 

     

    from zeep import Client
    from bs4 import BeautifulSoup


    class WebService:

    soap = 'Web Service URL'

    client = Client(soap)

    sid = client.service.login("username","pass")
    attributes = ['ref_num', 'open_date']
    objectType = "cr"
    whereClause = "open_date > 1519862400 AND open_date &lt; 1522368000"
    maxRows = -1
    tickets = client.service.doSelect(sid=sid, objectType=objectType, whereClause= whereClause, maxRows = maxRows, attributes=attributes)

    soup = BeautifulSoup(minim, 'xml')
    title = soup.find_all('AttrValue')
    print(titile)
    client.service.logout(p)

     

    It's works, but only read the first string of the array or the position what I tell to read, for example

     

    tickets = client.service.doSelect(sid=sid, objectType=objectType, whereClause= whereClause, maxRows = maxRows, attributes=attributes[1])

     

    there are no problem, but if I change again the variable for this:

     

    tickets = client.service.doSelect(sid=sid, objectType=objectType, whereClause= whereClause, maxRows = maxRows, attributes=str(attributes[ : ]))

     

    the method is always null in title, because the AttrValue is

    <AttrValue>'ref_num', 'open_date'</AttrValue>

     

    zeep is a class to connect to a WS and BeautifulSoup for read XML files, someone can help me?, somebody know other way to consume WS method?

    Forwards thanks!



  • 2.  Re: Webservice - using doSelect method with python

    Posted 04-20-2018 12:52 PM

    I really don't know Phyton, but maybe it are not understanding the tickets call.

     

    Maybe works if you try something like:

     

    tickets = client.service.doSelect("sid="+sid, "objectType="+objectType, "whereClause="+whereClause, "maxRows = "+maxRows, "attributes="+attributes[1])



  • 3.  Re: Webservice - using doSelect method with python

    Posted 04-20-2018 02:21 PM

    Carlos, with

    attributes = ["ref_num", "open_date"]

    I think you use

    attributes=attributes

    in the doSelect() call

    Thanks _Chi



  • 4.  Re: Webservice - using doSelect method with python
    Best Answer

    Posted 04-21-2018 01:14 PM

    Hi,

     

    Use below code based on the type and add your attributes.

     

    att_type = client.get_type('ns0:ArrayOfString')

    att = att_type(["ref_num", "open_date"])

     

    tickets = client.service.doSelect(sid=sid, objectType=objectType, whereClause= whereClause, maxRows = maxRows, attributes=att)

     

    It is working for me.

     

    Thank You

    Bakkiyaraj



  • 5.  Re: Webservice - using doSelect method with python

    Posted 04-23-2018 11:25 AM

    Thanks for the help, it works for me too, you must to say to zeep what kind of array you need to use (ArrayofString, ArrayofInt, etc). thanks for the help Bakkiyaraj