E-commerceFatturazione ElettronicaOdooopen sourceProgrammare col martelloTech notes

Accedere ai webservice soap con suds in Python

python programming programmazione da zero python

Accedere ai webservice con suds in Python

Installare suds per python 3

Il metodo più semplice è il fidato pip:

pip install suds-py3

Elencare i servizi disponibili

from suds.client import Client

client = Client("https://www.testfe.com/test_service.asmx?WSDL")

print(client)

Impostare lo schema

per alcuni tipi di servizio può essere necessario specificare lo schema.

from suds.xsd.doctor import Import, ImportDoctor

imp=Import('http://www.w3.org/2001/XMLSchema',location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://tempuri.org/')

Esempio completo

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

imp=Import('http://www.w3.org/2001/XMLSchema',location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://tempuri.org/')

client = Client("https://www.testfe.com/test_service.asmx?WSDL", doctor=ImportDoctor(imp))
#print(client) #Qui possiamo far stampare tutti i metodi disponibili, tra cui troveremo il nostro: TestMethod()

result = client.service.TestMethod()
print (result)

Comment here