python 带有 zeep 的 SOAP,requests.exception:403 客户端错误

python SOAP with zeep, requests.exception: 403 client error

我正在尝试使用 zeep 在 python 中创建一个 SOAP 客户端到目前为止,我在尝试将其添加到 运行 时运气为零。我不断收到以下错误。

Traceback (most recent call last):
  File "C:/Users/z905/PycharmProjects/Soap_Test/soap_test.py", line 14, in <module>
    client = Client(wsdl=client_location, transport=transport_with_basic_auth)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\client.py", line 134, in __init__
    self.wsdl = Document(wsdl, self.transport, strict=strict)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\wsdl\wsdl.py", line 81, in __init__
    root_definitions = Definition(self, document, self.location)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\wsdl\wsdl.py", line 178, in __init__
    self.parse_imports(doc)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\wsdl\wsdl.py", line 270, in parse_imports
    document = self.wsdl._get_xml_document(location)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\wsdl\wsdl.py", line 140, in _get_xml_document
    location, self.transport, self.location, strict=self.strict)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\loader.py", line 72, in load_external
    content = transport.load(url)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\transports.py", line 110, in load
    content = self._load_remote_data(url)
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\zeep\transports.py", line 126, in _load_remote_data
    response.raise_for_status()
  File "C:\Users\z905\PycharmProjects\Soap_Test\venv\lib\site-packages\requests\models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden (Forbidden port) for url: http://url:7104

我已经尝试过使用和不使用基本身份验证的程序。

from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport


client_location = "file://C:/<path-to-local-file>"
loc = "<url-to-wsdl>"

session = Session()
session.auth = HTTPBasicAuth('usrname', 'pass')
transport_with_basic_auth = Transport(session=session)

client = Client(wsdl=client_location, transport=transport_with_basic_auth)

以及没有基本授权的版本。

from zeep import Client
from zeep.wsse.username import UsernameToken


client_location = "file://C:/<path-to-local-file>"
loc = "<url-to-wsdl>"



client = Client(wsdl=loc, wsse=UsernameToken(usr, password, use_digest=True))

我通过执行以下操作解决了这个问题。该问题是由某些防火墙问题和代理不工作引起的。

import requests
session = requests.session()
session.trust_env = False

transport = Transport(session=session)
client = Client(wsdl=client_location, wsse=UsernameToken(usr, password, use_digest=True), transport=transport)