Is it possible to use python suds to read a wsdl file from the file system?

Question:

From suds documentation, I can create a Client if I have a url for the WSDL.

from suds.client import Client
url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url)

I currently have the WSDL file on my file system. Is it possible to use suds to read the WSDL file from my file system instead of hosting it on a web server?

Asked By: Thierry Lam

||

Answers:

try to use url='file:///path/to/file'

Answered By: Gabi Purcaru

Oneliner

# Python 3
import urllib, os 
url = urllib.parse.urljoin('file:', urllib.request.pathname2url(os.path.abspath("service.xml")))

This is a more complete one liner that will:

  • let you specify just the local path,
  • get you the absolute path,
  • and then format it as a file-url.

Based upon:

Original for reference

# Python 2 (Legacy Python)
import urlparse, urllib, os

url = urlparse.urljoin('file:', urllib.pathname2url(os.path.abspath("service.xml")))
Answered By: Josh Peak

Using pathlib:

from pathlib import Path
url = Path('resources/your_definition.wsdl').absolute().as_uri()
    
Answered By: Rubén Pozo
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.