Accessing Polarion WebServices via Python : Issues

Posts: 6
Joined: Tue Dec 13, 2011 8:48 am
Location: Valtra Inc. FI-44200 SUOLAHTI

Accessing Polarion WebServices via Python : Issues

Postby teropes » Tue Dec 13, 2011 9:00 am

Greetings Polarion users!

I'm having problems accessing Polarion WebServices via Python scripts. I'm using Python 2.5.4 with suds 0.4 as a SOAP Client.

The following quick and dirty snippet is trying to access a WorkItem from our Polarion server:

Code: Select all

from suds.client import Client

tracker_url = 'http://our_server/polarion/ws/services/TrackerWebService?wsdl'
session_url = 'http://our_server/polarion/ws/services/SessionWebService?wsdl'

# Session auth
username = "user"
password = "password"

# Init Client objects
session = Client(session_url)
tracker = Client(tracker_url)

    # Session login
    session.service.logIn(username, password)
    # session.service.beginTransaction()

    fields = ['id', 'title', 'description']
    wi = tracker.service.getWorkItemById("dev", "WI-42")
    print wi

    print "Failure"

It results in:
_unresolvable = True
_uri = "subterra:data-service:objects:/default/dev${WorkItem}WI-42"

What exactly does this _unresolvable indicate? I checked the logs from server and it shows my attempt as:
2011-12-13 10:43:29,272 [TP-Processor7] INFO - Session -5001506165221371995 created.
2011-12-13 10:43:29,272 [TP-Processor7] INFO - Logging in user admin into Session[-5001506165221371995]
2011-12-13 10:43:29,272 [TP-Processor7] INFO - User admin tries to log in from webservices
2011-12-13 10:43:29,272 [TP-Processor7] INFO - User admin logged in from webservices
2011-12-13 10:43:29,506 [TP-Processor7] INFO - Session 3387853522455761297 created.
2011-12-13 10:43:29,506 [TP-Processor7] INFO - LocalId[prototype WorkItem, object WI-42] (com.polarion.subterra.persistence.identification.UnknownObjectException)
2011-12-13 10:43:29,506 [TP-Processor7] INFO TXLOGGER - Tx 4d0da5d06370f_0_4d0da5d06370f_0_: finished. Time total: [ TIME 0,004986389 s. ], svn time total: [ TIME 0 s. ][] (0x), processed revs: [], write: false, rollback: false

My goal is simply to access WorkItem as an object, so that I can use the methods of the WorkItem class. Like "print wi.getName()". Once i get that function to work, I can do alot more fun with this WebServices thingy ;)

I also have question: Do i need to begin transaction <-> end transaction between actions such as query of workitems? My attempts of endTransaction(false) always leads to Java NullPointerException...?

I have seen some examples written in C# environment but I'm not interested in C#. Our automated test suite is written in Python and so that would be obviously our choice to interact with Polarion aswell.

Please comment, suggest, advice anything!

Tero Pesonen

Posts: 472
Joined: Tue Oct 24, 2006 10:27 am
Location: Polarion Software GmbH, Stuttgart

Re: Accessing Polarion WebServices via Python : Issues

Postby NickEntin » Wed Dec 14, 2011 8:45 am

Hi Tero,

I'm not an expert in Python, I'd recommend you to take a look on the SDK example in Java, make sure it works, and then translate it to Python, being sure that the logic is correct.

And no, for read operations you don't need transactions.

Best regards,

Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: Accessing Polarion WebServices via Python : Issues

Postby martins » Wed Dec 14, 2011 1:23 pm

I had the same problems when I tried to implement a webservice connection in PHP :-)

It's necessary to retrieve the sessionID from the answer of the login-request and use this sessionID in header of all following requests.

The extract from the log looks like your second request ("tracker.service.getWorkItemById...") is using another session then the first (login) request.

I don't know how to implement this in Python, in PHP I implemented it as follows:

Code: Select all

$wsSession  = new SoapClient($p_fqn."/polarion/ws/services/SessionWebService?wsdl",  array('trace' => 1));
$wsTracker  = new SoapClient($p_fqn."/polarion/ws/services/TrackerWebService?wsdl",  array('trace' => 1));

$wsSession->logIn(array("userName"=>$p_user, "password"=>$p_password));

$xResponse = new DOMDocument();

$header = new SoapHeader("", "sessionID", $xResponse->getElementsByTagName('sessionID')->item(0)->nodeValue, "0", "");

After adding the header to the $wsTracker everything works fine.

Maybe you can "translate" this from PHP to Python.


Posts: 6
Joined: Tue Dec 13, 2011 8:48 am
Location: Valtra Inc. FI-44200 SUOLAHTI

Re: Accessing Polarion WebServices via Python : Issues

Postby teropes » Thu Dec 15, 2011 1:26 pm

Thanks for your response martins.

How does the PHP function __setSoapHeaders() format the given array of data? It generates the Header tags of XML or what?

What is the exact content of your $header variable? Is it the SOAP-ENV:Header tag with the sessionID tag in it or some kind of an array of data? I'm confused here..

I have been playing around with my script now and got to the point where I can parse the sessionID from the login response envelope. Now I'm trying to format the header which i would set with client.set_option(soapheaders=<my_header>) but no luck so far. Still gettin the unresolvable = True response.

Is the proper format for session related soap header documented somewhere?

Posts: 6
Joined: Tue Dec 13, 2011 8:48 am
Location: Valtra Inc. FI-44200 SUOLAHTI

Re: Accessing Polarion WebServices via Python : Issues

Postby teropes » Fri Dec 16, 2011 1:30 pm

I have resolved this issue, thanks for the examples provided!

For future reference I will paste the working copy.

Format proper SOAP header with Python 2.5.4 and suds 0.4 -> Polarion WebServices API:

Code: Select all

# SessionService URL
ws_session_url = 'http://agfinaps152/polarion/ws/services/SessionWebService?wsdl'

# Init SOAP Client
session = Client(ws_session_url)

# Login
session.service.logIn(username, password)

 # parse sessionID from the login response envelope and format header
ssnid = login_response.getChild("soapenv:Envelope").getChild("soapenv:Header").getChild("ns1:sessionID").getText()
sid = Element('sessionID', ns=('ns1','')).setText(ssnid)
must_understand = Attribute("SOAP-ENV:mustUnderstand", "0")
actor = Attribute("SOAP-ENV:actor", "")

# set SOAP header

print sid (confirmed as working header):

Code: Select all

<ns1:sessionID xmlns:ns1="" SOAP-ENV:mustUnderstand="0" SOAP-ENV:actor="">4404955032591469296</ns1:sessionID>
   <ns1:session xmlns:ns1="" SOAP-ENV:mustUnderstand="0">-2719686666748149143</ns1:session>

Tero Pesonen

Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 30 guests