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

3

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?

Kissable answered 28/10, 2010 at 19:49 Comment(0)
S
59

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

Sarraute answered 28/10, 2010 at 19:51 Comment(1)
To add to Thierry's comment, it also has to be an absolute path. (eg. file:///home/admin/service.xml)Barberabarberry
U
20

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")))
Unwrap answered 20/2, 2015 at 2:11 Comment(2)
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")))Flapper
that solved my problem that appeared when switching from python 3.8.x to 3.9.2Liminal
Q
2

Using pathlib:

from pathlib import Path
url = Path('resources/your_definition.wsdl').absolute().as_uri()
    
Quartziferous answered 29/10, 2020 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.