2

我的命令: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()
4

1 回答 1

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})."
        )
于 2021-05-06T16:48:47.660 回答