1

蟒蛇:2.7.6

齐普:1.1.0

我正在尝试访问 Web 服务 URL 的 WSDL 端点。我目前正在使用 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,因此我正在为我的帖子更改它。

在我的代码中,我有以下内容

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',))

我不确定为什么它可以通过浏览器/curl 而不是 python SOAP 客户端工作。我应该在端点 URL 中更改某些内容,例如稍后设置端口吗?我用 suds 尝试过,但由于 URL 无效,它给了我一个 404 错误。我应该如何解决这个问题/我还能尝试什么?

提前致谢!

4

2 回答 2

1

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

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

如果您可以分享您是如何测试 URL 的,这将非常有帮助。

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

于 2017-03-06T21:27:50.317 回答
-1

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

http://12.345.678.90:8080/PathGoesHere?wsdl

http://12.345.678.90:8080/PathGoesHere?singleWsdl

成功了

于 2017-03-07T19:07:41.863 回答