How to access Spira v3.x SOAP web services using Python ?

Thursday, October 17, 2013
Avatar
I have to access SpiraTest SOAP web service for python.

So, Can I get knowledge base code for SOAP service for Spiratest using Python ?
3 Replies
Friday, October 25, 2013
Avatar
re: nilesh Thursday, October 17, 2013

Hi Nilesh

You would use something like:

from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
from suds.wsse import *

WDSLFile = http://mySpiraServer.com/SpiraTeam/Services/v4_0/ImportExport.svc?wsdl
client = Client(WDSLFile,doctor=schema_doctor)
resp = client.service.Connection_Authenticate("myUsername","myPassword")

Regards

Adam

Thursday, July 17, 2014
Avatar
re: inflectra.david Friday, October 25, 2013
It seems the answer provided by Adam is incomplete (where is that schema_doctor variable defined?) but at least it pointed me to the right place: http://stackoverflow.com/questions/3760427/problem-accessing-wsdl-service-with-python-suds-raises-typenotfound-arrayofint

For reference, here is a re-transcript of the solution:
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor

# Obviously I made this up    
wsdl_url = 'http://whatever/path/to/wsdl'

# Fix missing types with ImportDoctor
schema_url = 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
schema_import = Import(schema_url)
schema_doctor = ImportDoctor(schema_import)

# Pass doctor to Client
client = Client(url=wsdl_url, doctor=schema_doctor)

Friday, May 5, 2023
Avatar
re: nilesh Thursday, October 17, 2013

SOAP stands for Simple Object Access Protocol, as the name suggests nothing but a protocol for exchanging structured data between nodes. It uses XML instead of JSON.

In this article, we are going to see how to make SOAP API calls using python. If you want to test out what exactly the payload and response would look like, you can use the below curl command:

 

Method 1: Using a request

First, we import the requests library, then we define the SOAP URL. 

 

The next and most important step is to format the XML body according to the structure provided in the SOAP URL. To know the format, simply visit the SOAP URL, click the CountryISOCode link, and format the XML accordingly.

Then you simply prepare the headers and make the POST call.

Code:

import requests
# SOAP request URL
url = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
  
# structured XML
payload = """<?xml version=\"1.0\" encoding=\"utf-8\"?>
            <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
                <soap:Body>
                    <CountryIntPhoneCode xmlns=\"http://www.oorsprong.org/websamples.countryinfo\">
                        <sCountryISOCode>IN</sCountryISOCode>
                    </CountryIntPhoneCode>
                </soap:Body>
            </soap:Envelope>"""
# headers
headers = {
    'Content-Type': 'text/xml; charset=utf-8'
}
# POST request
response = requests.request("POST", url, headers=headers, data=payload)
  
# prints the response
print(response.text)
print(response)

The web service domain is defined in an XML schema file (XSD) that Spring-WS will automatically export as a WSDL. Create an XSD file with operations to return a country’s name, population, capital, and currency.  For more details about the course check out this link learn selenium includes all topics of Selenium such as Features, Selenium vs QTP, Selenium Tool Suits, Selenium IDE, Selenium IDE Locating Strategies, Selenium WebDriver, WebDriver Features, WebDriver vs RC, WebDriver Installation, etc.

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Thursday, October 17, 2013
  • Last Reply: Friday, May 5, 2023
  • Replies: 3
  • Views: 10284