42

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?

Thierry Lam
  • 45,304
  • 42
  • 117
  • 144

3 Answers3

59

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

sherpya
  • 4,890
  • 2
  • 34
  • 50
Gabi Purcaru
  • 30,940
  • 9
  • 79
  • 95
  • 9
    To add to Thierry's comment, it also has to be an absolute path. (eg. file:///home/admin/service.xml) – trinth May 09 '12 at 16:14
19

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")))
Josh Peak
  • 5,898
  • 4
  • 40
  • 52
  • 1
    In case someone is using python3, the names have changed: `import urllib, os` `url = urllib.parse.urljoin('file:', urllib.request.pathname2url(os.path.abspath("service.xml")))` – Sebastian Jul 01 '17 at 09:51
  • that solved my problem that appeared when switching from python 3.8.x to 3.9.2 – jabba Mar 12 '21 at 09:47
2

Using pathlib:

from pathlib import Path
url = Path('resources/your_definition.wsdl').absolute().as_uri()
    
ericbn
  • 10,163
  • 3
  • 47
  • 55
Rubén Pozo
  • 1,035
  • 1
  • 12
  • 23