9

i'm testing out SUDS library and I'm trying to make a simple request to an endpoint but i get unusual output. Why?

from suds.client import Client
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)

url = "http://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/Gateway"

client = Client(url)
print client

Output:

Martynass-MacBook-Air:CH martynas$ python ch.py
DEBUG:suds.xsd.schema:loaded:

schema collection
   Schema:0x109a7db90
   (raw)
      <schema/>
   (model)

DEBUG:suds.xsd.schema:MERGED:
Schema:0x109a7db90
(raw)
   <schema/>
(model)
chuckfinley
  • 2,577
  • 10
  • 32
  • 42
  • You should rephrase the question to "I'm looking to use SUDS with a particular endpoint, but I don't know the WSDL" – Wyrmwood Dec 17 '13 at 21:31

4 Answers4

6

You can't use suds for this servce, suds is based on SOAP, which is another web service protocol. What you can do is send an xml request and get a response.

import requests

target_url = "http://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/Gateway"
headers={'Content-type': 'text/xml'}
print requests.post(target_url, data=xml, headers=headers).text

Where the xml is defined according to their schemes. http://xmlgw.companieshouse.gov.uk/example_http.html This is one examaple

xml = ('''
<GovTalkMessage xmlns="http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader" 
xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 
xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader">
<EnvelopeVersion>1.0</EnvelopeVersion>
<Header>
<MessageDetails>
<Class>CompanyDetails</Class>
<Qualifier>request</Qualifier>
<TransactionID>14456553</TransactionID>
</MessageDetails>
<SenderDetails>
<IDAuthentication>
<SenderID>My_SenderID</SenderID>
<Authentication>
<Method>CHMD5</Method>
<Value>e999e113407884fa410fa2f53bc23952</Value>
</Authentication>
</IDAuthentication>
<EmailAddress>sometest@some.email.address</EmailAddress>
</SenderDetails>
</Header>
<GovTalkDetails>
<Keys/>
</GovTalkDetails>
<Body>
<CompanyDetailsRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/CoDets.xsd">
<CompanyNumber>01002361</CompanyNumber>
<GiveMortTotals>1</GiveMortTotals>
</CompanyDetailsRequest>
</Body>
</GovTalkMessage>
''')

<Class>CompanyDetails</Class> What type of info you're getting. kinda what "function" to call

<Authentication>
<Method>CHMD5</Method>
<Value>e999e113407884fa410fa2f53bc23952</Value>
</Authentication>
</IDAuthentication>
Here you would put the login info i guess

<CompanyDetailsRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/CoDets.xsd"> <CompanyNumber>01002361</CompanyNumber> <GiveMortTotals>1</GiveMortTotals> </CompanyDetailsRequest> The "function" call and it's parameters

Now this will give me a response telling me the authorization failed. So if you have an account there, this should work for you.

Here you can find the list of schemes they have for different types of request. Some of them have sample request to help you out. http://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/SchemaStatusOutput

Here is the complete guide of all their schemes. http://xmlgw.companieshouse.gov.uk/data_usage_guide_dec_2013.pdf

M4rtini
  • 13,186
  • 4
  • 35
  • 42
  • I think this is for information retrieval only? Can you actually submit stuff using this? – chuckfinley Dec 14 '13 at 10:07
  • I assume so. But from what i could see that looked like a information retrieval site. But you have to submit the parameters when doing the inquiries, so submitting information should work the same way. – M4rtini Dec 14 '13 at 12:18
2

There aren't any wsdl definitions for that site. Try something like http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL for your url then you can try something like client.service.GetWeatherInformation()

From the suds document, "You will need to know the url for WSDL for each service used."

An explicit example

from suds.client import Client
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)

url = " http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"

client = Client(url)
client.service.GetWeatherInformation()

Outputs a ton of data.

Wyrmwood
  • 3,340
  • 29
  • 33
  • Where can i find it? Check out these links: http://xmlgw.companieshouse.gov.uk/SchemaStatus http://xmlgw.companieshouse.gov.uk/msgenv.html – chuckfinley Dec 11 '13 at 10:37
  • Do you want to check out SUDS (as your question states) or do you want to check out the services on this website? I would think the latter is not a question for this forum, rather for someone at the web site. – Wyrmwood Dec 11 '13 at 15:50
  • "Looking for a a complete example on how to make a request." - how is this not clear? – chuckfinley Dec 12 '13 at 08:38
2

Suds does not make it easy to discover the service, it's better to first test a bit with soapui or generate a human-readable doc of the wsdl with this xslt : http://code.google.com/p/wsdl-viewer/ . So you know the structure of requests and replies, and which services are available.

Requests and responses in soap are xml trees, so once you get the result, you need to access the content of the xml tag that contains the information you're interested in. Here is an example that should work ( I don't have a username, but the result.Status.Success works ).

import suds

client = suds.client.Client("http://webservices.data-8.co.uk/companieshouse.asmx?WSDL")
result = client.service.GetCompanyDetails("username", "password", 1234)
print result.Status.Success
print result.Result.CompanyName
vincent
  • 6,368
  • 3
  • 25
  • 23
1

You can not make a request against .xsd. XSD is definition of the exchanged message. You must make a request against webservice Looking here you can find more info about that web service. But also there is pricing page indicating that you must pay to use their service. Probably when you pay you will get username and password to authenticate with the service.

Saša Šijak
  • 8,717
  • 5
  • 47
  • 82