suds.TypeNotFound 错误

suds.TypeNotFound error

我正在尝试连接到 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 年前的 post 获得的信息开始使用 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))

如您所见,这几乎就是我的出发点,但它对我不起作用。

提前感谢任何提示。

以下将消除您的 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/Whosebug/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 756, in create
    return fn(schema, root)
  File "/usr/local/.virtualenvs/Whosebug/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 376, in __init__
    TypedContent.__init__(self, schema, root)
  File "/usr/local/.virtualenvs/Whosebug/lib/python2.7/site-packages/suds/xsd/sxbase.py", line 95, in __init__
    self.name = root.get('name')
  File "/usr/local/.virtualenvs/Whosebug/lib/python2.7/site-packages/suds/sax/element.py", line 234, in get
    attr = self.getAttribute(name, ns)
  File "/usr/local/.virtualenvs/Whosebug/lib/python2.7/site-packages/suds/sax/element.py", line 404, in getAttribute
    prefix, name = splitPrefix(name)
  File "/usr/local/.virtualenvs/Whosebug/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

所以,也许试试另一个 soap 客户端,比如 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')

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

解决了这个问题