def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None, timeout=30): # cliente soap del web service if wrapper: Http = set_http_wrapper(wrapper) self.Version = WSFEv1.Version + " " + Http._wrapper_version if isinstance(proxy, dict): proxy_dict = proxy else: proxy_dict = parse_proxy(proxy) if H**O or not wsdl: wsdl = WSDL if not wsdl.endswith("?WSDL") and wsdl.startswith("http"): wsdl += "?WSDL" if not cache or H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') self.__log("Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict)) self.client = SoapClient( wsdl = wsdl, cache = cache, proxy = proxy_dict, cacert = cacert, timeout = timeout, trace = "--trace" in sys.argv) return True
def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None, timeout=30): # cliente soap del web service if timeout: self.__log("Estableciendo timeout=%s" % (timeout, )) socket.setdefaulttimeout(timeout) if wrapper: Http = set_http_wrapper(wrapper) self.Version = WSCOC.Version + " " + Http._wrapper_version proxy_dict = parse_proxy(proxy) location = LOCATION if H**O or not wsdl: wsdl = WSDL elif not wsdl.endswith("?wsdl") and wsdl.startswith("http"): location = wsdl wsdl += "?wsdl" elif wsdl.endswith("?wsdl"): location = wsdl[:-5] if not cache or H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') self.__log("Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict)) self.client = SoapClient( wsdl = wsdl, cache = cache, proxy = proxy_dict, ns="coc", cacert=cacert, soap_ns="soapenv", soap_server="jbossas6", trace = "--trace" in sys.argv) # corrijo ubicación del servidor (http en el WSDL) self.client.services['COCService']['ports']['COCServiceHttpSoap11Endpoint']['location'] = location self.__log("Corrigiendo location=%s" % (location, )) return True
def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None, timeout=30, soap_server=None): "Conectar cliente soap del web service" try: # analizar transporte y servidor proxy: if wrapper: Http = set_http_wrapper(wrapper) self.Version = self.Version + " " + Http._wrapper_version if isinstance(proxy, dict): proxy_dict = proxy else: proxy_dict = parse_proxy(proxy) self.log("Proxy Dict: %s" % str(proxy_dict)) if self.H**O or not wsdl: wsdl = self.WSDL # agregar sufijo para descargar descripción del servicio ?WSDL o ?wsdl if not wsdl.endswith(self.WSDL[-5:]) and wsdl.startswith("http"): wsdl += self.WSDL[-5:] if not cache or self.H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') # deshabilitar verificación cert. servidor si es nulo falso vacio if not cacert: cacert = None elif cacert is True: # usar certificados predeterminados que vienen en la biblioteca cacert = os.path.join(httplib2.__path__[0], 'cacerts.txt') if not os.path.exists(cacert): cacert = None # wrong version, certificates not found... self.log("Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict)) # analizar espacio de nombres (axis vs .net): ns = 'ser' if self.WSDL[-5:] == "?wsdl" else None self.client = SoapClient( wsdl = wsdl, cache = cache, proxy = proxy_dict, cacert = cacert, timeout = timeout, ns = ns, soap_server = soap_server, trace = "--trace" in sys.argv) self.cache = cache # utilizado por WSLPG y WSAA (Ticket de Acceso) self.wsdl = wsdl # utilizado por TrazaMed (para corregir el location) # corrijo ubicación del servidor (puerto http 80 en el WSDL AFIP) for service in self.client.services.values(): for port in service['ports'].values(): location = port['location'] if location and location.startswith("http://"): warnings.warn("Corrigiendo WSDL ... %s" % location) location = location.replace("http://", "https://").replace(":80", ":443") port['location'] = location return True except: ex = traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback) self.Traceback = ''.join(ex) try: self.Excepcion = traceback.format_exception_only( sys.exc_type, sys.exc_value)[0] except: self.Excepcion = u"<no disponible>" if self.LanzarExcepciones: raise return False
def __init__( self, location, enctype="multipart/form-data", trace=False, cacert=None, timeout=30, proxy=None, ): kwargs = {} kwargs["timeout"] = timeout kwargs["disable_ssl_certificate_validation"] = cacert is None kwargs["ca_certs"] = cacert if proxy: if isinstance(proxy, dict): proxy_dict = proxy else: proxy_dict = parse_proxy(proxy) print("using proxy", proxy_dict) import socks kwargs["proxy_info"] = httplib2.ProxyInfo( proxy_type=socks.PROXY_TYPE_HTTP, **proxy_dict) self.http = httplib2.Http(**kwargs) self.trace = trace self.location = location self.enctype = enctype self.cookies = None self.method = "POST" self.referer = None
def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None): # cliente soap del web service try: if wrapper: Http = set_http_wrapper(wrapper) self.Version = TrazaMed.Version + " " + Http._wrapper_version proxy_dict = parse_proxy(proxy) if H**O or not wsdl: wsdl = WSDL location = LOCATION if not wsdl.endswith("?wsdl") and wsdl.startswith("http"): location = wsdl wsdl += "?wsdl" elif wsdl.endswith("?wsdl"): location = wsdl[:-5] if not cache or H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') if "--trace" in sys.argv: print "Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict) self.client = SoapClient( wsdl = wsdl, cache = cache, proxy = proxy_dict, ns="tzmed", cacert=cacert, soap_ns="soapenv", soap_server="jetty", trace = "--trace" in sys.argv) # corrijo ubicación del servidor (localhost:9050 en el WSDL) if 'IWebServiceService' in self.client.services: ws = self.client.services['IWebServiceService'] # version 1 else: ws = self.client.services['IWebService'] # version 2 ws['ports']['IWebServicePort']['location'] = location # Establecer credenciales de seguridad: self.client['wsse:Security'] = { 'wsse:UsernameToken': { 'wsse:Username': self.Username, 'wsse:Password': self.Password, } } return True except: ex = traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback) self.Traceback = ''.join(ex) try: self.Excepcion = traceback.format_exception_only( sys.exc_type, sys.exc_value)[0] except: self.Excepcion = u"<no disponible>" return False
def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None, timeout=30, soap_server=None): "Conectar cliente soap del web service" try: # analizar transporte y servidor proxy: if wrapper: Http = set_http_wrapper(wrapper) self.Version = self.Version + " " + Http._wrapper_version if isinstance(proxy, dict): proxy_dict = proxy else: proxy_dict = parse_proxy(proxy) if self.H**O or not wsdl: wsdl = self.WSDL # agregar sufijo para descargar descripción del servicio ?WSDL o ?wsdl if not wsdl.endswith(self.WSDL[-5:]) and wsdl.startswith("http"): wsdl += self.WSDL[-5:] if not cache or self.H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') self.log("Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict)) # analizar espacio de nombres (axis vs .net): ns = 'ser' if self.WSDL[-5:] == "?wsdl" else None self.client = SoapClient(wsdl=wsdl, cache=cache, proxy=proxy_dict, cacert=cacert, timeout=timeout, ns=ns, soap_server=soap_server, trace="--trace" in sys.argv) self.cache = cache # utilizado por WSLPG y WSAA (Ticket de Acceso) self.wsdl = wsdl # utilizado por TrazaMed (para corregir el location) return True except: ex = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback) self.Traceback = ''.join(ex) try: self.Excepcion = traceback.format_exception_only( sys.exc_type, sys.exc_value)[0] except: self.Excepcion = u"<no disponible>" if self.LanzarExcepciones: raise return False
def Conectar(self, cache=None, url="", proxy=""): "Establecer la conexión a los servidores de la AFIP" if H**O or not url: url = WSDL if not cache or H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') proxy_dict = parse_proxy(proxy) self.client = SoapClient(url, wsdl=url, cache=cache, trace='--trace' in sys.argv, ns='ctg', soap_ns='soapenv', exceptions=True, proxy=proxy_dict) return True
def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None, timeout=30, soap_server=None): "Conectar cliente soap del web service" try: # analizar transporte y servidor proxy: if wrapper: Http = set_http_wrapper(wrapper) self.Version = self.Version + " " + Http._wrapper_version if isinstance(proxy, dict): proxy_dict = proxy else: proxy_dict = parse_proxy(proxy) if self.H**O or not wsdl: wsdl = self.WSDL # agregar sufijo para descargar descripción del servicio ?WSDL o ?wsdl if not wsdl.endswith(self.WSDL[-5:]) and wsdl.startswith("http"): wsdl += self.WSDL[-5:] if not cache or self.H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, "cache") self.log("Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict)) # analizar espacio de nombres (axis vs .net): ns = "ser" if self.WSDL[-5:] == "?wsdl" else None self.client = SoapClient( wsdl=wsdl, cache=cache, proxy=proxy_dict, cacert=cacert, timeout=timeout, ns=ns, soap_server=soap_server, trace="--trace" in sys.argv, ) self.cache = cache # utilizado por WSLPG y WSAA (Ticket de Acceso) self.wsdl = wsdl # utilizado por TrazaMed (para corregir el location) return True except: ex = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback) self.Traceback = "".join(ex) try: self.Excepcion = traceback.format_exception_only(sys.exc_type, sys.exc_value)[0] except: self.Excepcion = u"<no disponible>" if self.LanzarExcepciones: raise return False
def Conectar(self, cache=None, wsdl=None, proxy="", wrapper=None, cacert=None, timeout=30, soap_server=None): "Conectar cliente soap del web service" try: # analizar transporte y servidor proxy: if wrapper: Http = set_http_wrapper(wrapper) self.Version = self.Version + " " + Http._wrapper_version if isinstance(proxy, dict): proxy_dict = proxy else: proxy_dict = parse_proxy(proxy) self.log("Proxy Dict: %s" % str(proxy_dict)) if self.H**O or not wsdl: wsdl = self.WSDL # agregar sufijo para descargar descripción del servicio ?WSDL o ?wsdl if not wsdl.endswith(self.WSDL[-5:]) and wsdl.startswith("http"): wsdl += self.WSDL[-5:] if not cache or self.H**O: # use 'cache' from installation base directory cache = os.path.join(self.InstallDir, 'cache') # deshabilitar verificación cert. servidor si es nulo falso vacio if not cacert: cacert = None elif cacert is True or cacert.lower() == 'default': # usar certificados predeterminados que vienen en la biblioteca try: import certifi cacert = certifi.where() except ImportError: cacert = os.path.join(httplib2.__path__[0], 'cacerts.txt') elif cacert.startswith("-----BEGIN CERTIFICATE-----"): pass else: if not os.path.exists(cacert): self.log("Buscando CACERT en conf...") cacert = os.path.join(self.InstallDir, "conf", os.path.basename(cacert)) if cacert and not os.path.exists(cacert): self.log("No se encuentra CACERT: %s" % str(cacert)) warnings.warn("No se encuentra CACERT: %s" % str(cacert)) cacert = None # wrong version, certificates not found... raise RuntimeError( "Error de configuracion CACERT ver DebugLog") return False self.log("Conectando a wsdl=%s cache=%s proxy=%s" % (wsdl, cache, proxy_dict)) # analizar espacio de nombres (axis vs .net): ns = 'ser' if self.WSDL[-5:] == "?wsdl" else None self.client = SoapClient(wsdl=wsdl, cache=cache, proxy=proxy_dict, cacert=cacert, timeout=timeout, ns=ns, soap_server=soap_server, trace="--trace" in sys.argv) self.cache = cache # utilizado por WSLPG y WSAA (Ticket de Acceso) self.wsdl = wsdl # utilizado por TrazaMed (para corregir el location) # corrijo ubicación del servidor (puerto http 80 en el WSDL AFIP) for service in list(self.client.services.values()): for port in list(service['ports'].values()): location = port['location'] if location and location.startswith("http://"): warnings.warn("Corrigiendo WSDL ... %s" % location) location = location.replace("http://", "https://").replace( ":80", ":443") # usar servidor real si en el WSDL figura "localhost" localhost = 'https://localhost:' if location.startswith(localhost): url = urlparse(wsdl) location = location.replace( "localhost", url.hostname) location = location.replace(":9051", ":443") port['location'] = location return True except BaseException: ex = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) self.Traceback = ''.join(ex) try: self.Excepcion = traceback.format_exception_only( sys.exc_info()[0], sys.exc_info()[1])[0] except BaseException: self.Excepcion = "<no disponible>" if self.LanzarExcepciones: raise return False