即使由於缺乏該服務的憑證而無法驗證它是否正常工作,也應該從suds
開始。 只需創建一個HRDPartnerAPI
實例,調用add_authheader
與.service.<methodname>(<args...>)
import suds.client
from suds.sax.element import Element
from suds.sax.attribute import Attribute
class HRDPartnerAPI(object):
NS = "https://www.hrd.pl/partnerAPI/"
PARTNER = "http://www.hrd.pl/partnerAPI/Partner.php?wsdl"
DOMAIN = "https://www.hrd.pl/partnerAPI/Domain.php?wsdl"
CERTIFICATE = "https://www.hrd.pl/partnerAPI/Certificate.php?wsdl"
CLIENT = "https://www.hrd.pl/partnerAPI/Client.php?wsdl"
POLL = "https://www.hrd.pl/partnerAPI/Poll.php?wsdl"
INVOICE = "https://www.hrd.pl/partnerAPI/Invoice.php?wsdl"
def __init__(self, wsdl):
self.client = suds.client.Client(wsdl)
self.service = self.client.service
def add_authheader(self, username, password):
auth = Element('AuthHeader');
login = Element('uid').setText(username)
secret = Element('pass').setText(password)
auth.append(login);
auth.append(secret);
self.client.set_options(soapheaders=[auth])
def list_methods(self):
return [method for method in self.client.wsdl.services[0].ports[0].methods]
domain = HRDPartnerAPI(wsdl=HRDPartnerAPI.DOMAIN)
print domain.list_methods() # unauth
print domain.service.check("lala.com") # unauth
print domain.service.validateAuthInfo("hrd.pl","abcd") # unauth
print domain.add_authheader("__partner_uid__", "__encoded_cspNr_and_pass__") # add auth info
print domain.service.check("lala.com") # authenticated
print domain.client.last_sent() # DEBUG: show last sent msg, shows AuthHeader is present.
print domain.client.last_received() # DEBUG: show last recv. msg
輸出添加AuthHeader
,並調用任何方法:
[info, domainInSystem, check, changeDns, changePrivacy, createHost, transfer, register, trade, validateAuthInfo, renew, validateTradePw, transferDelete, listByClient, tradeStatus, privacyAddDomain, listAll, privacyRemoveDomain]
{"status":false,"errorCode":"1032","error":"Auth Error"}
{"status":false,"errorCode":"1032","error":"Auth Error"}
None
{"status":false,"errorCode":"1032","error":"Auth Error"}
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://www.hrd.pl/partnerAPI/" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<AuthHeader>
<uid>__partner_uid__</uid>
<pass>__encoded_cspNr_and_pass__</pass>
</AuthHeader>
</SOAP-ENV:Header>
<ns2:Body>
<ns1:check>
<domains xsi:type="ns3:string">lala.com</domains>
</ns1:check>
</ns2:Body>
</SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:checkResponse>
<return xsi:type="xsd:string">{"status":false,"errorCode":"1032","error":"Auth Error"}</return>
</ns1:checkResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>