从suds到zeep的连接错误?

2024-03-29 12:21:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将我的SOAP客户机从suds using转换为zeep,但是我得到了一个连接错误。似乎我需要实现一个代理,但我尝试了没有工作。你知道吗

这是工作的原始肥皂水代码:

import urllib2
from suds.client import Client
from suds.transport.http import HttpTransport

class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
    def __init__(self, key, cert):
        urllib2.HTTPSHandler.__init__(self)
        self.key = key
        self.cert = cert

    def https_open(self, req):
        return self.do_open(self.getConnection, req)

    def getConnection(self, host, timeout=300):
        return http.client.HTTPSConnection(host,
                                   key_file=self.key,
                                   cert_file=self.cert)

class HTTPSClientCertTransport(HttpTransport):
    def __init__(self, key, cert, *args, **kwargs):
        HttpTransport.__init__(self, *args, **kwargs)
        self.key = key
        self.cert = cert

    def u2open(self, u2request):
        tm = self.options.timeout
        url = urllib2.build_opener(HTTPSClientAuthHandler(self.key, self.cert))
        if self.u2ver() < 2.6:
            socket.setdefaulttimeout(tm)
            return url.open(u2request)
        else:
            return url.open(u2request, timeout=tm)

    client = Client(adds,location=loc,
        transport = HTTPSClientCertTransport(cert_filename,key_filename),timeout=10)
    LastBatchUID=client.service.getDispatchBatchesSinceUID('-1')

以及上面代码的zeep端口:

import os
from requests import Session
from zeep import Client
from zeep.transports import Transport

loc = 'https://adssta.caiso.com:447/ADS/APIWebService/v7'
adds = 'https://adssta.caiso.com:447/ADS/APIWebService/v7?WSDL'

key_filename = "certificates\\XXXX_ADSx1234.pem"
cert_filename = "certificates\\XXXX_ADSx1234key.pem"

session = Session()
session.verify = False
session.cert = (key_filename, cert_filename)

transport = Transport(session=session, timeout=10)

client = Client(adds,transport=transport)

client.wsdl.dump()

service = client.bind('APIWebService', 'APIWebServicePort')

LastBatchUID=client.service.getDispatchBatchesSinceUID('-1')

WSDL文件转储文件

Bindings:
     Soap11Binding: {http://ads.caiso.com/api/webservices/dispatch/v7}APIWebServiceBinding

Service: APIWebService
     Port: APIWebServicePort (Soap11Binding: {http://ads.caiso.com/api/webservices/dispatch/v7}APIWebServiceBinding)
         Operations:
            getBatchHeader(batchUID: xsd:string) -> result: xsd:string
            getBatchStatus(batchUID: xsd:string) -> result: xsd:int
            getDispatchBatch(batchUID: xsd:string) -> result: xsd:string
            getDispatchBatchesSinceUID(batchUID: xsd:string) -> result: xsd:string
            getTrajectoryData(batchUID: xsd:string) -> result: xsd:string
            isNewTrajData(batchUID: xsd:string) -> result: xsd:boolean
            submitMSSLFRequest(request: xsd:string) -> result: xsd:string
            validateDispatchBatch(batchUID: xsd:string) -> None

但当我真的尝试打电话时,我得到了以下错误:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='fpapjbos141.wepex.net', port=8443): Max retries exceeded with url: /ADS/APIWebService/v7 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001ED504C7080>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

Tags: keyfromimportselfclientstringcertdef