使用Zeep调用BRENDA数据库API遇AttributeError问题求助
The issue here is that Zeep handles SOAP method calls differently than SOAPpy — you can't call methods directly on the Client object. Instead, you need to access the service layer exposed by the WSDL. Here's how to fix your code:
Step 1: Verify Available Services and Methods
First, let's inspect what services and methods Zeep has parsed from the BRENDA WSDL to confirm getKmValue exists:
import zeep import hashlib wsdl = "https://www.brenda-enzymes.org/soap/brenda.wsdl" password = hashlib.sha256("xx".encode('utf-8')).hexdigest() parameters = "xxx," + password + ",ecNumber*{}#organism*{}#".format("2.7.1.2", "Homo sapiens") client = zeep.Client(wsdl=wsdl) # Print all available services in the WSDL print("Available services:", list(client.wsdl.services.keys())) # For the BRENDA WSDL, the service is typically 'BrendaService' service = client.wsdl.services['BrendaService'].ports['BrendaPort'] # Print all methods exposed by this port print("Available methods:", [op.name for op in service.operations])
This will show you exactly what method names you can use (in case there's a capitalization difference like GetKmValue instead of getKmValue).
Step 2: Call the Method Correctly
Once you confirm getKmValue is available, use the client.service attribute to access the SOAP methods (Zeep binds to the default service/port automatically):
import zeep import hashlib wsdl = "https://www.brenda-enzymes.org/soap/brenda.wsdl" password = hashlib.sha256("xx".encode('utf-8')).hexdigest() parameters = "xxx," + password + ",ecNumber*{}#organism*{}#".format("2.7.1.2", "Homo sapiens") client = zeep.Client(wsdl=wsdl) # Access the service layer and call the method km_string = client.service.getKmValue(parameters) print(km_string)
Fallback: Explicitly Specify Service and Port
If the above doesn't work, explicitly target the service and port from the WSDL:
import zeep import hashlib wsdl = "https://www.brenda-enzymes.org/soap/brenda.wsdl" password = hashlib.sha256("xx".encode('utf-8')).hexdigest() parameters = "xxx," + password + ",ecNumber*{}#organism*{}#".format("2.7.1.2", "Homo sapiens") client = zeep.Client(wsdl=wsdl) # Get the specific service and port brenda_service = client.wsdl.services['BrendaService'] brenda_port = brenda_service.ports['BrendaPort'] # Call the method directly on the port km_string = brenda_port.getKmValue(parameters) print(km_string)
This should resolve the AttributeError since you're now accessing the method through the correct service/port layer instead of the base Client object.
内容的提问来源于stack exchange,提问作者Natasha

