【问题标题】:suds.TypeNotFound errorsuds.TypeNotFound 错误
【发布时间】:2015-09-01 08:29:34
【问题描述】:

我正在尝试连接到http://data.opensolution.se/index.php?wsdl 并使用以下代码:

from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import

url = 'http://data.opensolution.se/index.php?wsdl'
imp = Import('http://www.w3.org/2001/XMLSchema',
location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://data.opensolution.se/')
client = Client(url, doctor=ImportDoctor(imp))

但它会抛出错误:

suds.TypeNotFound TypeNotFound: 找不到类型: '(xml, http://www.w3.org/2001/XMLSchema, )'

我也尝试过在 imp.filter.add 中添加的内容,例如:

imp.filter.add('http://data.opensolution.se/soap/OSDataService')

我从 5 年前的帖子中获取信息开始使用 ImportDoctor:SOAP suds and the dreaded schema Type Not Found error

那里找到的代码有效:

from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor

url = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl'
imp = Import('http://www.w3.org/2001/XMLSchema',
    location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://WebXml.com.cn/')
client = Client(url, doctor=ImportDoctor(imp))

正如你所看到的,这几乎是我开始的,但它对我不起作用。

提前感谢您的任何提示。

【问题讨论】:

    标签: python soap suds


    【解决方案1】:

    以下将摆脱您的Type not found 错误:

    from suds.client import Client
    from suds.xsd.doctor import Import, ImportDoctor
    url = 'http://data.opensolution.se/index.php?wsdl'
    imp = Import('http://www.w3.org/2001/XMLSchema')
    doctor = ImportDoctor(imp)
    client = Client(url, doctor=doctor)
    

    但你可能会遇到这个错误:https://fedorahosted.org/suds/ticket/239

    导致:

      File "/usr/local/.virtualenvs/stackoverflow/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 756, in create
        return fn(schema, root)
      File "/usr/local/.virtualenvs/stackoverflow/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 376, in __init__
        TypedContent.__init__(self, schema, root)
      File "/usr/local/.virtualenvs/stackoverflow/lib/python2.7/site-packages/suds/xsd/sxbase.py", line 95, in __init__
        self.name = root.get('name')
      File "/usr/local/.virtualenvs/stackoverflow/lib/python2.7/site-packages/suds/sax/element.py", line 234, in get
        attr = self.getAttribute(name, ns)
      File "/usr/local/.virtualenvs/stackoverflow/lib/python2.7/site-packages/suds/sax/element.py", line 404, in getAttribute
        prefix, name = splitPrefix(name)
      File "/usr/local/.virtualenvs/stackoverflow/lib/python2.7/site-packages/suds/sax/__init__.py", line 49, in splitPrefix
        if isinstance(name, basestring) \
    RuntimeError: maximum recursion depth exceeded while calling a Python object
    

    所以,也许试试另一个肥皂客户端,比如SOAPpy

    用 pip 安装:

    pip install soappy
    

    以下示例改编自本教程:http://www.diveintopython.net/soap_web_services/introspection.html

    >>> from SOAPpy import WSDL
    >>> wsdlFile = 'http://data.opensolution.se/index.php?wsdl'
    >>> server = WSDL.Proxy(wsdlFile)
    >>> server.methods.keys()
    [u'GetFlightPrepackById', u'GetMdbArticles', u'CardPurchase', u'GetNewArticleNumber', u'GetAccountingAccounts', u'ExportZ', u'AddBookingQuote', u'DeleteTableBooking', u'GetTravelDepartures', u'SaveCashRegister', u'DecreaseTravelBooking', u'GetEventLog', u'GetCustomersByCategory', u'DeleteCustomer', u'SaveCurrencies', u'GetReportArticleRating', u'GetXReport', u'GetEmployeeBySearch', u'SaveMdbCategories', u'LetoUnlockOrder', u'GetFlightPrepackArticlesByPrepackId', u'GetTableByNo', u'GetOrdersByFlightId', u'RemoveFlightPrepackById', u'GetCustomers', u'GetReports', u'GetCityBreakBooking', u'GetArticleOption', u'AddBookingQuoteArticle', u'GetGiftCardOrdersByOrderId', u'SaveVatAccount', u'GetOrder', u'GetEmployeeCategories', u'GetBooking', u'GetCashRegisterCategoryById', u'AddLoyaltyRecord', u'SaveArticle', u'GetDibsTokens', u'GetCode', u'AddFlightStaffByFlightId', u'GetEventLogCategories', u'SavePaymentAccount', u'GetEmployeeCategoryById', u'RemoveFlightStaffByFlightId', u'GetOrders', u'ResetSamportOrder', u'GetStartPage', u'SaveCurrency', u'GetZArticleReport', u'GetFlightRoutes', u'GetFlightNumberByNumber', u'GetOrdersByDate', u'GetCardTypeByName', u'GetRebateCategories', u'SaveInvoice', u'GetArticles', u'GetTablesByStatus', u'GetCardReportByDate', u'NewCard', u'GetFlightNumberById', u'GetEmployees', u'GetArticleById', u'GetTableCategoryById', u'GetBookingByDate', u'GetCardGroups', u'SaveCardReportTransaction', u'GetArticlesBySearch', u'RegisterBackup', u'GetFlightByZ', u'GetCardTransactions', u'GetOrdersFromInvoice', u'ExportEmployees', u'LetoDeleteOrder', u'CardFill', u'UpdateCard', u'GetEmployeeByWaiterId', u'SaveEmployeeCategory', u'GetTableById', u'SaveAccount', u'DeleteFlightPrepackArticleByPrepackId', u'SaveCustomer', u'GetFlightsByDate', u'SaveStartPageButton', u'GetCardReportBatch', u'GetActiveCodes', u'GetAccountingCategories', u'CCUGetControlCode', u'GetCustomerCategoryById', u'GetSales', u'GetFlightCommission', u'GetEvents', u'ChangeCitybreakBooking', u'AddSamportOrder', u'GetTravelOrders', u'GetCustomerCategories', u'DeleteStartPage', u'LetoGetOpenOrders', u'GetCards', u'GetAccountingPaymentMethods', u'GetGiftCardByMagCardNo', u'GetGiftCardOrdersByGiftCardId', u'CCUGetSerialNumber', u'GetAccountDistributionByReportId', u'GetReportsByDate', u'GetGrandArticleReport', u'GetNewEmployeeNumber', u'GetFlightPrepacksByDelivered', u'LetoAddOrder', u'SaveAccountingVatAccount', u'GetFlightById', u'GetCard', u'GetFlightStaffByFlightId', u'GetCustomerById', u'GetReportByDateAndFlightNr', u'DeleteCurrency', u'GetGiftCardById', u'GetTravelPrice', u'SaveDibsToken', u'GetEventLogTypes', u'GetArticleImage', u'LetoChangeOrder', u'GetFlightPrepacksByFlightId', u'GetXArticleReport', u'LetoGetOrderInfo', u'GetTravelRoutes', u'GetTableOrder', u'AddFlightPrepackArticleByPrepackId', u'GetOrdersByTime', u'GetArticleOptions', u'SaveActiveCode', u'GetFlightPrepacksBySearch', u'GetAccountingAccount', u'SaveCardReportBatch', u'GetRebateCategoriesMap', u'GetGiftCardOrdersByDate', u'GetPlaces', u'GetCustomerBySearch', u'GetLoyaltyRecords', u'GetCardsByCardGroup', u'GetFlightNumbers', u'GetReportsByFlightId', u'GetInvoices', u'DeleteCitybreakBooking', u'ExportArticles', u'GetArticleCategories', u'DeleteSamportOrder', u'GetArticleTypes', u'GetInvoiceById', u'GetAccountingVat', u'GetTravelPrices', u'GetReportById', u'GetMdbCategoriesArticles', u'GetCompanies', u'GetReportByDate', u'GetCompanyById', u'GetCashRegistersByCategory', u'GetCardReportLatest', u'SaveFlightNumber', u'SaveCompany', u'SaveCustomerCategory', u'GetReportHeadersByFlightId', u'GetCashRegistersBySearch', u'ExportOrders', u'GenerateReport', u'GetTravelOrder', u'GetGiftCardsByCustomerId', u'LetoPayByCash', u'SaveMdbArticles', u'GetMdbCategories', u'ExportInvoices', u'SaveArticleOption', u'GetCodes', u'GetOrdersByFilter', u'GetRebateGroups', u'GetGiftCards', u'CreateCitybreakBooking', u'ExportOrdersWithArticles', u'SaveCashRegisterCategory', u'CardCancel', u'GetArticleCategoryById', u'DeleteAccountingAccount', u'GetCodeCategories', u'GetArticlesByCategory', u'GetTravelStops', u'GetCashRegisterById', u'GetTableStatus', u'GetCardGroup', u'CardRefund', u'IncreaseTravelBooking', u'ExportCustomers', u'GetFlightPrepacksByStatus', u'GetFlightsByFlightNr', u'GetAccounts', u'SaveAccountingAccount', u'GetInvoiceByOrderId', u'GetDatabaseName', u'GetTablesByCategoryId', u'GetStartPages', u'GetTableCategories', u'SaveStartPage', u'SaveAccountingPaymentMethodAccount', u'UpdateFlightPrepackArticleByPrepackId', u'GetCashRegisterCategories', u'GetActiveCode', u'SaveTableBooking', u'LetoAbortOrder', u'GetCurrencies', u'GetCashRegisters', u'GetReportsByLimit', u'GetFlightTerminals', u'SaveArticleCategory', u'GetCardTypeById', u'GetTravelOrdersByDeparture', u'SaveEmployee', u'GetRebateCategory', u'GetOrdersByReportId', u'DeleteStartPageButton', u'GetCardByCardNo', u'GetEmployeesByCategory', u'GetEmployeeById', u'DeleteActiveCode', u'GetTables']
    >>> callInfo = server.methods['GetTables']
    >>> callInfo.inparams
    [<wstools.WSDLTools.ParameterInfo instance at 0x2aeaa2823bd8>]
    >>> callInfo.inparams[0].name
    u'ApiKey'
    >>> callInfo.inparams[0].type
    (u'http://www.w3.org/2001/XMLSchema', u'string')
    >>> callInfo.outparams
    [<wstools.WSDLTools.ParameterInfo instance at 0x2aeaa2823c20>]
    >>> callInfo.outparams[0].name
    u'return'
    >>> callInfo.outparams[0].type
    (u'http://www.w3.org/2001/XMLSchema', u'string')
    

    【讨论】:

    • 谢谢!我还不能投票给你(SO 的长期潜伏者,但是全新的帐户),但我已经接受了答案。 soapPy 立即生效。
    • 乐于助人。干杯!
    【解决方案2】:

    我遇到了同样的问题,最终通过将我使用的 suds-py3 1.4.1.0 客户端更改为 suds-jurko==0.6 解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2015-03-25
      相关资源
      最近更新 更多