Is it possible to use python suds to read a wsdl file from the file system?
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?
try to use url='file:///path/to/file'
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:
- the comments in the accepted answer and
- this https://stackoverflow.com/a/14298190/622276
- and thanks to user Sebastian the updated Python 3 implementation since we should avoid writing legacy python at this time.
Original for reference
# Python 2 (Legacy Python)
import urlparse, urllib, os
url = urlparse.urljoin('file:', urllib.pathname2url(os.path.abspath("service.xml")))
Using pathlib:
from pathlib import Path
url = Path('resources/your_definition.wsdl').absolute().as_uri()
精彩评论