mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.89k stars 586 forks source link

Unable to resolve type #943

Open ninigij opened 5 years ago

ninigij commented 5 years ago

Hi, I'm trying to write a Powerschool API and I'm getting this error:

Traceback (most recent call last):
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 578, in _get_component
    return items[qname]
KeyError: <lxml.etree.QName object at 0x7fc7103bef58>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 451, in _resolve_dict
    new = obj.resolve()
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/types/complex.py", line 326, in resolve
    self._extension = self._extension.resolve()
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/types/unresolved.py", line 21, in resolve
    retval = self.schema.get_type(self.qname)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 147, in get_type
    return self._get_instance(qname, 'get_type', 'type')
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 255, in _get_instance
    raise last_exception
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 251, in _get_instance
    return method(qname)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 536, in get_type
    return self._get_component(qname, self._types, 'type')
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 593, in _get_component
    location=self._location)
zeep.exceptions.LookupError: No type 'Enum' in namespace http://www.w3.org/2001/XMLSchema. Available types are: {http://www.w3.org/2001/XMLSchema}dateTime, {http://www.w3.org/2001/XMLSchema}ENTITIES, {http://www.w3.org/2001/XMLSchema}NCName, {http://www.w3.org/2001/XMLSchema}negativeInteger, {http://www.w3.org/2001/XMLSchema}base64Binary, {http://www.w3.org/2001/XMLSchema}gYear, {http://www.w3.org/2001/XMLSchema}string, {http://www.w3.org/2001/XMLSchema}token, {http://www.w3.org/2001/XMLSchema}gYearMonth, {http://www.w3.org/2001/XMLSchema}ID, {http://www.w3.org/2001/XMLSchema}float, {http://www.w3.org/2001/XMLSchema}hexBinary, {http://www.w3.org/2001/XMLSchema}IDREF, {http://www.w3.org/2001/XMLSchema}QName, {http://www.w3.org/2001/XMLSchema}duration, {http://www.w3.org/2001/XMLSchema}time, {http://www.w3.org/2001/XMLSchema}int, {http://www.w3.org/2001/XMLSchema}nonNegativeInteger, {http://www.w3.org/2001/XMLSchema}anySimpleType, {http://www.w3.org/2001/XMLSchema}unsignedShort, {http://www.w3.org/2001/XMLSchema}long, {http://www.w3.org/2001/XMLSchema}ENTITY, {http://www.w3.org/2001/XMLSchema}Name, {http://www.w3.org/2001/XMLSchema}NOTATION, {http://www.w3.org/2001/XMLSchema}gDay, {http://www.w3.org/2001/XMLSchema}decimal, {http://www.w3.org/2001/XMLSchema}boolean, {http://www.w3.org/2001/XMLSchema}date, {http://www.w3.org/2001/XMLSchema}anyURI, {http://www.w3.org/2001/XMLSchema}byte, {http://www.w3.org/2001/XMLSchema}NMTOKENS, {http://www.w3.org/2001/XMLSchema}unsignedByte, {http://www.w3.org/2001/XMLSchema}gMonthDay, {http://www.w3.org/2001/XMLSchema}unsignedLong, {http://www.w3.org/2001/XMLSchema}short, {http://www.w3.org/2001/XMLSchema}positiveInteger, {http://www.w3.org/2001/XMLSchema}integer, {http://www.w3.org/2001/XMLSchema}unsignedInt, {http://www.w3.org/2001/XMLSchema}IDREFS, {http://www.w3.org/2001/XMLSchema}language, {http://www.w3.org/2001/XMLSchema}nonPositiveInteger, {http://www.w3.org/2001/XMLSchema}double, {http://www.w3.org/2001/XMLSchema}anyType, {http://www.w3.org/2001/XMLSchema}NMTOKEN, {http://www.w3.org/2001/XMLSchema}normalizedString, {http://www.w3.org/2001/XMLSchema}gMonth

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/chase/pslogin/test.py", line 9, in <module>
    main()
  File "/home/chase/pslogin/test.py", line 5, in main
    api = powerschoolapi.PowerSchoolAPI('https://sisavrsb.ednet.ns.ca', 'pearson', 'm0bApP5')
  File "/home/chase/pslogin/powerschoolapi.py", line 51, in __init__
    self.setup()
  File "/home/chase/pslogin/powerschoolapi.py", line 64, in setup
    settings=Settings(raw_response=True, force_https=True)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/client.py", line 62, in __init__
    wsdl, self.transport, settings=self.settings)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 84, in __init__
    root_definitions = Definition(self, document, self.location)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 183, in __init__
    self.parse_types(doc)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 316, in parse_types
    self.types.add_documents(schema_nodes, self.location)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 118, in add_documents
    document.resolve()
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 470, in resolve
    _resolve_dict(self._types)
  File "/home/chase/.local/lib/python3.5/site-packages/zeep/xsd/schema.py", line 463, in _resolve_dict
    'parent': obj.qname,
zeep.exceptions.LookupError: Unable to resolve type {http://www.w3.org/2001/XMLSchema}Enum in None. (via {http://sdk.pcas.pss.pearson.com/xsd}EncryptionType)

As you can see from the code, I've tried turning strict mode off and using every setting available to get it working. Despite turning off strict mode and requesting the raw XML response, it still tries parsing it then complains.

from requests.auth import HTTPDigestAuth
from requests import Session
from zeep import Client, exceptions
from zeep.transports import Transport
from zeep.settings import Settings

class PowerschoolAPI:
    def __init__(self, url, api_username:str = 'pearson', api_password:str = 'm0bApP5'):
        self.url_ = url
        self.session_ = Session()
        self.session_.auth = HTTPDigestAuth(api_username, api_password)
        self.api_username_ = api_username
        self.api_password_ = api_password
        self.setup()

    def setup(self):
        public_portal_service_url = self.url_ + '/pearson-rest/services/PublicPortalServiceJSON'
        settings = Settings(strict=False, raw_response=True, forbid_dtd=False, forbid_entities=False, forbid_external=False, xsd_ignore_sequence_order=True)
        self.client_ = Client(wsdl=public_portal_service_url + '?wsdl', transport=Transport(session=self.session_), settings=settings)

    def login(self, username, password):
        print(self.client_.service.loginToPublicPortal(username, password))
        #print(self.client_.loginToPublicPortal(username, password))

    url_ = None
    session_ = None
    api_username_ = None
    api_password_ = None
    client_ = None

api = powerschoolapi.PowerschoolAPI('http://sales.powerschool.com', 'pearson', 'm0bApP5')

This exact same error has happened with two different schools' Powerschool SOAP APIs. The WSDL is here. Use 'pearson' as the username and 'm0bApP5' for the password (this is the default credentials, I'm not exposing anything that isn't publicly available). I'm using the latest zeep version. Thanks!

WhyNotHugo commented 4 years ago

I'm having the exact same error with this WSDL file, and I've no idea what the error means. The file itself seems to be valid, at least per some validators I've found:

http://desarrollo.urbano.com.ar/webservice/?wsdl

Have you managed to get this working somehow?

Kesha2447 commented 3 days ago

It is still relevant