python3 zeep url给出401客户端错误:未经授权的url

时间:2018-03-19 13:40:14

标签: python python-3.x soap http-status-code-401 zeep

我的命令:python3 -mzeep https://pearson:m0bApP5@cms.powerschool.com/pearson-rest/services/PublicPortalServiceJSON?wsdl

我收到错误: requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://pearson:m0bApP5@cms.powerschool.com/pearson-rest/services/PublicPortalServiceJSON?wsdl

转到https://cms.powerschool.com/pearson-rest/services/PublicPortalServiceJSON?wsdl并使用pearson和m0bApP5手动验证,但为什么不这样做?

我也试过使用这段代码,但它也没用。

#!/usr/bin/env python3
from zeep import Client
from requests.auth import HTTPBasicAuth  # or HTTPDigestAuth, or OAuth1, etc.
from requests import Session
from zeep.transports import Transport
session = Session()
session.auth = HTTPBasicAuth("pearson","m0bApP5")
url = "https://cms.powerschool.com/pearson-rest/services/PublicPortalServiceJSON?wsdl"
stransport = Transport(session=session)
client = Client(url,transport=stransport)
client.wsdl.dump()

1 个答案:

答案 0 :(得分:0)

您应该像这样使用 HTTPDigestAuth:

session = requests.session()
session.auth = requests.auth.HTTPDigestAuth(api_username, api_password)
self.url = base_url + "pearson-rest/services/PublicPortalServiceJSON"
try:
    self.client = zeep.Client(
        wsdl=self.url + "?wsdl",
        transport=zeep.transports.Transport(session=session),
    )
except requests.exceptions.ConnectionError:
        raise APIException(f"Could not connect to {base_url}.")
    except requests.exceptions.HTTPError:
        raise APIException(
            f"Incorrect api credentials ({api_username}, {api_password})."
        )