Python: Making a request with suds
Asked Answered
R

4

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)
Rolfston answered 8/12, 2013 at 0:3 Comment(1)
You should rephrase the question to "I'm looking to use SUDS with a particular endpoint, but I don't know the WSDL"Tisza
Y
7

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>[email protected]</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

Yevette answered 12/12, 2013 at 23:56 Comment(2)
I think this is for information retrieval only? Can you actually submit stuff using this?Rolfston
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.Yevette
T
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.

Tisza answered 10/12, 2013 at 19:47 Comment(3)
Where can i find it? Check out these links: xmlgw.companieshouse.gov.uk/SchemaStatus xmlgw.companieshouse.gov.uk/msgenv.htmlRolfston
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.Tisza
"Looking for a a complete example on how to make a request." - how is this not clear?Rolfston
G
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
Gules answered 15/12, 2013 at 22:10 Comment(0)
E
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.

Errol answered 10/12, 2013 at 10:53 Comment(1)
you must submit requests to this endpoint xmlgw.companieshouse.gov.uk/v1-0/xmlgw/GatewayIsomerism

© 2022 - 2024 — McMap. All rights reserved.