2017-03-28 2 views
0

sudsクライアントを使用してapiにリクエストを送信しようとしています。sudsクライアントのヘッダを正しく設定する方法

要求は、このように形成されています

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v20="https://API"> 
    <soapenv:Header> 
     <v20:apiHeader> 
     <v20:username>username</v20:username> 
     <v20:password>password</v20:password> 
     <!--Optional:--> 
     <v20:name>?</v20:name> 
     </v20:apiHeader> 
    </soapenv:Header> 
    <soapenv:Body> 
     <v20:getLoginDetails/> 
    </soapenv:Body> 
</soapenv:Envelope> 

私はこのような要求を送信しています:

client = Client('https://wsdl', faults=False) 

client.set_options(headers={'username': username 'authToken': auth_token, 'name': ''}) 
client.service.getLoginDetails() 

私は受け付けており、エラーがある:

(<HTTPStatus.INTERNAL_SERVER_ERROR: 500>, (Fault){ 
    faultcode = "soap:Server" 
    faultstring = "apiHeader should not be null" 
    detail = "" 
}) 

はこれですどのように私は要求を送信する必要がありますか?それは間違いなく私が思うapiHeaderと関係があります。わからないが、私はこの使用して同じエラーが何を得る:

username = Element('username').setText(name) 
     password= Element('password').setText(pass) 
     header_list = [username, pass] 
     self.client.set_options(soapheaders=header_list) 
     return self.client.service.getLoginDetails() 

答えて

0

を私はこれに似たものを使用して、この作品を作りました:

from suds.sax.element import Element 
from suds.sax.attribute import Attribute 
code = Element('serviceCode').setText('PABB4BEIJING') 
pwd = Element('servicePwd').setText('QWERTPABB') 

reqsoapheader = Element('ReqSOAPHeader').insert(code) 
reqsoap_attribute = Attribute('xmlns', "http://schemas.acme.eu/") 
reqsoapheader.append(reqsoap_attribute) 

client.set_options(soapheaders=reqsoapheader) 
関連する問題