2016-10-31 72 views
1

私はsudsによって作成されたXMLオブジェクトに署名しようとしていましたが、私は運がありません。PythonでXMLに署名する方法(suds)

現在のスクリプトは次のようになります。

from suds.client import Client 
from suds.transport.http import HttpAuthenticated 
from suds.transport import Reply, TransportError 

import requests 

class RequestsTransport(HttpAuthenticated): 

    def __init__(self, **kwargs): 
     self.cert = kwargs.pop('cert', None) 
     HttpAuthenticated.__init__(self, **kwargs) 

    def send(self, request): 
     self.addcredentials(request) 
     resp = requests.post(
      request.url, 
      data=request.message, 
      headers=request.headers, 
      cert=self.cert, 
      verify=True 
     ) 
     result = Reply(resp.status_code, resp.headers, resp.content) 
     return result 

url = 'URL' 
headers = {"Content-Type": "text/xml;charset=UTF-8", 
      "SOAPAction": ""} 
t = RequestsTransport(cert=("path to cert","path to key")) 
client = Client(url, headers=headers, transport=t) 

私はメソッドを作成し、署名する必要があります。私はチェックしているWSDLの公開証明書のためのpemファイルを持っています。また

、私は私が取得要求に署名いけない場合:私はそれのpython-WSSE(https://py-wsse.readthedocs.io/en/latest/)作品を見つけ

答えて

1

「ヘッダの処理中にエラーが発見された」:

suds.WebFault:サーバー上げ障害を魅力のような泡で。

from suds.client import Client 
    from suds.wsse import Security, Timestamp 
    from wsse.suds import WssePlugin 

    def get_client(our_keyfile_path, our_certfile_path, their_certfile_path): 
     wsse = Security() 
     wsse.tokens.append(Timestamp()) 

     return Client(
      wsdl_url, 
      transport=transport, 
      wsse=wsse, 
      plugins=[ 
       WssePlugin(
        keyfile=our_keyfile_path, 
        certfile=our_certfile_path, 
        their_certfile=their_certfile_path, 
       ), 
      ], 
     ) 
関連する問題