Python 网络服务:尝试使用 zeep SOAP 客户端连接到 WSDL 端点时出现连接错误

Python web services: Trying to connect to WSDL endpoint using zeep SOAP client gives connection error

Python: 2.7.6

zeep: 1.1.0

我正在尝试访问 Web 服务的 WSDL 端点 URL。我目前正在使用 zeep SOAP 客户端,也尝试过 suds(并获得了类似的结果)。当我从 Web 访问 URL 或向其发送 curl 请求时,我会收到响应并可以看到服务。但是,当我尝试从 zeep(使用 python -mzeep [url] 命令)或 suds(仅通过 print(client))访问它时,出现连接错误。

urllib2.URLError: <urlopen error [Errno -2] Name or service not known>

我在下面粘贴了完整的错误。不幸的是,我无法在这里分享 URL,所以我正在为我的 post 更改它。

在我的代码中有以下内容

from zeep import Client
endpoint_url = 'http://12.345.678.90:8080/PathGoesHere?wsdl'
client = Client(endpoint_url)

我也试过以下

sudo python -mzeep http://12.345.678.90:8080/PathGoesHere?wsdl

错误:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/zeep/__main__.py", line 86, in <module>
    main(args)
  File "/usr/local/lib/python2.7/dist-packages/zeep/__main__.py", line 75, in main
    client = Client(args.wsdl_file, transport=transport)
  File "/usr/local/lib/python2.7/dist-packages/zeep/client.py", line 120, in __init__
    self.wsdl = Document(wsdl, self.transport)
  File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/wsdl.py", line 65, in __init__
    root_definitions = Definition(self, document, self.location)
  File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/wsdl.py", line 156, in __init__
    self.parse_types(doc)
  File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/wsdl.py", line 272, in parse_types
    self.types.add_documents(schema_nodes, self.location)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/schema.py", line 96, in add_documents
    document = self.create_new_document(node, location)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/schema.py", line 183, in create_new_document
    schema.load(self, node)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/schema.py", line 349, in load
    visitor.visit_schema(node)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/visitor.py", line 108, in visit_schema
    self.process(node, parent=parent)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/visitor.py", line 49, in process
    result = visit_func(self, node, parent)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/visitor.py", line 155, in visit_import
    schema_node = load_external(location, self.schema._transport)
  File "/usr/local/lib/python2.7/dist-packages/zeep/xsd/utils.py", line 59, in load_external
    response = transport.load(url)
  File "/usr/local/lib/python2.7/dist-packages/zeep/transports.py", line 111, in load
    content = self._load_remote_data(url)
  File "/usr/local/lib/python2.7/dist-packages/zeep/transports.py", line 126, in _load_remote_data
    response = self.session.get(url, timeout=self.load_timeout)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 487, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='host.goes.here', port=8080): Max retries exceeded with url: /PathGoesHere?xsd=xsd0 (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fbf2c442390>: Failed to establish a new connection: [Errno -2] Name or service not known',))

我不确定为什么它可以通过 browser/curl 而不是 python SOAP 客户端。我应该在端点 URL 中更改某些内容,例如稍后设置端口吗?我用肥皂水尝试过,但由于 URL 无效,它给了我一个 404 错误。我应该如何处理这个 problem/what 否则我可以试试吗?

提前致谢!

我首先想到的是,你在防火墙后面吗?这不是有线错误,只是因为 URL 不可访问。

对于大多数公司环境,您可以通过浏览器访问 URL 但不能从命令行(或 python 库)访问它。原因是,公司政策已应用于您的计算机,浏览器使用代理脚本 (pac) 文件来确定使用哪个代理。

如果您能分享您是如何测试 URL 的,那将非常有帮助。

能否请您简单地使用命令 ping 来测试 URL 是否可以访问。

在我的情况下,似乎将我的 url 端点从

更改为
http://12.345.678.90:8080/PathGoesHere?wsdl

http://12.345.678.90:8080/PathGoesHere?singleWsdl

成功了