Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/10/2017, 22:14
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Cotización de las monedas

Hola a todos, quería hacerles la siguiente consulta: Un amigo y yo estamos viendo en python usando requests y suds trabajando en memoria porque creemos que sería muy costoso el depender de un archivo.

Este es el código:

Código Python:
Ver original
  1. from suds.client import Client
  2. from suds.sudsobject import asdict
  3. from suds.cache import NoCache
  4. import requests
  5. import simplejson as json
  6.  
  7. def get_wsdl_def(wsdl_url, headers, cacert, def_file):
  8.     if not (wsdl_url and cacert and headers):
  9.         print("\n\tFaltan parámetros")
  10.     else:
  11.         res = requests.get(wsdl_url, headers=headers, verify=cacert)
  12.         if res:
  13.             try:
  14.                 with open(def_file, 'w') as f:
  15.                     f.write(res.content)
  16.                 res = True
  17.             except:
  18.                 print("\n\tVerificar parámetros")
  19.     return res
  20.  
  21. if __name__ == '__main__':
  22.     client = Client("https://cotizaciones.bcu.gub.uy/wscotizaciones/servlet/awsbcucotizaciones?wsdl")
  23.     print client
  24.     # configurables    
  25.     x_cacert   = "Autoridad_Certificadora_Raiz_Nacional_de_Uruguay.crt" # agesic/correos
  26.     x_wsdl_url = "https://cotizaciones.bcu.gub.uy/wscotizaciones/servlet/awsbcucotizaciones?wsdl"
  27.     x_headers  = {'a':'b'}
  28.     x_def_file = "/tmp/awsbcucotizaciones.xml"
  29.     get_wsdl_def(x_wsdl_url, x_headers, x_cacert, x_def_file)
  30.     wsdl_def_url  = 'file://' +  x_def_file
  31.     fdesde = "2017/10/11"
  32.     fhasta = "2017/10/11"
  33.     grupo  = 2              # 1. mercado internacional 2. mercado local
  34.     moneda = {'item':2225}  # Dolar USA Billete
  35.     ok = get_wsdl_def(x_wsdl_url, x_headers, x_cacert, x_def_file)
  36.     if ok:
  37.         #client = Client(wsdl_def_url, cache=NoCache())
  38.         client = Client(json.dumps(requests.get(wsdl_def_url, headers=x_headers, verify=x_cacert)), cache=NoCache())
  39.        
  40.         cotiza_obj = client.factory.create("wsbcucotizacionesin")
  41.         cotiza_obj.FechaDesde = fdesde
  42.         cotiza_obj.FechaHasta = fhasta
  43.         cotiza_obj.Grupo  = grupo
  44.         cotiza_obj.Moneda = moneda
  45.         ret = client.service.Execute(cotiza_obj)
  46.         cotizacion = asdict(ret.datoscotizaciones).items()[0][1][0]
  47.         fecha =  cotizacion.Fecha.strftime("%d-%m-%Y")
  48.         print("\n\t %s \n\t Fecha: %s\n\t Tipo Comprador: %s \n" % (cotizacion.Nombre, fecha, cotizacion.TCV,))
  49.     else:
  50.         print("\n\t%s\n" % ("Algo salió mal... :( ",))

El error que nos da es éste:

Traceback (most recent call last):
File "/home/detectivejd/NetBeansProjects/Python/cotizacion_bcu/cotizaciones.py", line 40, in <module>
client = Client(json.dumps(requests.get(wsdl_def_url, headers=x_headers, verify=x_cacert)), cache=NoCache())
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 553, in send
adapter = self.get_adapter(url=request.url)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 598, in get_adapter
raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for 'file:///tmp/awsbcucotizaciones.xml'

No sé que nos sugieren para arreglar esto, esperamos sus respuestas y saludos.