【问题标题】:Is it possible to use python suds to read a wsdl file from the file system?是否可以使用 python suds 从文件系统中读取 wsdl 文件?
【发布时间】:2011-05-02 02:10:11
【问题描述】:

如果我有 WSDL 的 URL,我可以从 suds documentation 创建一个 Client

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

我的文件系统上目前有 WSDL 文件。是否可以使用 suds 从我的文件系统中读取 WSDL 文件,而不是将其托管在 Web 服务器上?

【问题讨论】:

    标签: python soap wsdl suds


    【解决方案1】:

    尝试使用url='file:///path/to/file'

    【讨论】:

    • 要添加到 Thierry 的评论中,它还必须是绝对路径。 (例如:file:///home/admin/service.xml)
    【解决方案2】:

    Oneliner

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

    这是一个更完整的班轮,它将:

    • 让你只指定本地路径,
    • 给你绝对路径,
    • 然后将其格式化为文件 URL。

    基于:

    原文供参考

    # Python 2 (Legacy Python)
    import urlparse, urllib, os
    
    url = urlparse.urljoin('file:', urllib.pathname2url(os.path.abspath("service.xml")))
    

    【讨论】:

    • 万一有人在用python3,名字变了:import urllib, osurl = urllib.parse.urljoin('file:', urllib.request.pathname2url(os.path.abspath("service.xml")))
    • 解决了我从 python 3.8.x 切换到 3.9.2 时出现的问题
    【解决方案3】:

    使用路径库:

    def wsdl_uri():
        import pathlib
        return pathlib.Path(os.path.abspath("resources/your_definition.wsdl")).as_uri()
        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多