[Python-es] Duda con SUDS (consumir web service)

Eduard Diaz eventgrafic en gmail.com
Lun Nov 14 20:21:25 CET 2011


Genial :D,

por un tema de compatibilidad te recomiendo que la cabecera la acabes con
un "\r\n\r\n" tipo:

print "Content-type: text/html\r\n\r\n"

"\r\n" es la secuencia que define el final de línea CRLF,

Es lo correcto segun la especificacion del protocolo:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2

"HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all
protocol elements except the entity-body (see appendix 19.3 for
tolerant applications). The end-of-line marker within an entity-body is
defined by its associated media type, as described in section 3.7."

Un saludo

...y ya nos contarás como te va con el webservice :)



El 14 de noviembre de 2011 19:28, pavel fuentes <pafuco05 en gmail.com>escribió:

> Tenías razón Eduard, era la cabecera, gracias, ahora ya me queda bien:
>
> #!/Python26/python
> from suds.client import Client
> url = 'http://localhost:7789/?wsdl'
> client = Client(url)
> #print client
> d = client.service.say_hello('punk', 5)
> print "Content-type: text/html"
> print
> print "<html><head>"
> print ""
> print "</head><body>"
> print d
> print "</body></html>"
>
>
> On 11/14/11, pavel fuentes <pafuco05 en gmail.com> wrote:
> > No podría ser la forma en que manipulo un stringArray en python?
> >
> > Si pongo el siguiente código:
> >
> > #!/Python26/python
> > from suds.client import Client
> > url = 'http://localhost:7789/?wsdl'
> > client = Client(url)
> > print client
> >
> > Va bien y me sale en el navegador:
> >
> > Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build:
> > R699-20100913
> >
> > Service ( HelloWorldService ) tns="rpclib.examples.hello.soap"
> >    Prefixes (1)
> >       ns0 = "rpclib.examples.hello.soap"
> >    Ports (1):
> >       (Application)
> >          Methods (1):
> >             say_hello(xs:string name, xs:integer times, )
> >          Types (3):
> >             say_hello
> >             say_helloResponse
> >             stringArray
> >
> > Pero si agrego las 2 últimas líneas ya me da error 500:
> >
> > #!/Python26/python
> > from suds.client import Client
> > url = 'http://localhost:7789/?wsdl'
> > client = Client(url)
> > #print client
> > d = client.service.say_hello('punk', 5)
> > print d
> >
> >
> >
> > On 11/14/11, Eduard Diaz <eventgrafic en gmail.com> wrote:
> >> Si, un error de sintaxis
> >>
> >> No estas construyendo correctamente la cabecera.
> >>
> >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
> >>
> >>
> >>
> >> El 14 de noviembre de 2011 17:50, pavel fuentes
> >> <pafuco05 en gmail.com>escribió:
> >>
> >>> Sí, tienes razón, he mirado el log de apache.
> >>>
> >>>  Aparece:
> >>>
> >>> [Mon Nov 14 11:14:54 2011] [error] [client 127.0.0.1] malformed header
> >>> from script. Bad header=(stringArray){: sudo.py
> >>>
> >>> Incorporé un ciclo  for .. in al código. Ahora me queda
> >>>
> >>> #!/Python26/python
> >>> from suds.client import Client
> >>> url = 'http://localhost:7789/?wsdl'
> >>> client = Client(url)
> >>> saludo = client.service.say_hello('punk', 5)
> >>> for elemento in saludo:
> >>>  print elemento
> >>>
> >>> El log de error ahora es:
> >>>  [Mon Nov 14 11:48:08 2011] [error] [client 127.0.0.1] malformed
> >>> header from script. Bad header=('string', [Hello, punk, Hello: sudo.py
> >>>
> >>> ERROR DE SINTAXIS ???
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On 11/14/11, Carlos Herrera Polo <carlos.herrerapolo en gmail.com> wrote:
> >>> > Ayudaria bastante si envias el error que debe estar en el log de
> >>> > apache
> >>> >
> >>> > El 14/11/11, pavel fuentes <pafuco05 en gmail.com> escribió:
> >>> >> Hola a todos, alguien me puede ayudar con SUDS, quizás es un error
> de
> >>> >> concepto que tengo.
> >>> >>
> >>> >> Mi ambiente es windows xp sp3 y apache 2.2.8
> >>> >>
> >>> >> Empecé con web service recientemente, tengo en mi directorio de
> >>> >> apache
> >>> >> el clásico ejemplo
> >>> >> helloworld_soap.py
> >>> >>
> >>> >> Cuando accedo a él desde la línea de comandos de python todo va bien
> >>> >> y
> >>> >> obtengo mi respuesta en la consola. El código en la línea de
> comandos
> >>> >> es el siguiente:
> >>> >>
> >>> >> from suds.client import Client
> >>> >> url = 'http://localhost:7789/?wsdl'
> >>> >> client = Client(url)
> >>> >> client.service.say_hello('punk', 5)
> >>> >>
> >>> >> Sin embargo, si hago un fichero .py y trato de acceder desde el
> >>> >> navegador(http://localhost/sudo.py) obtengo un 500 Internal Server
> >>> >> Error. Aquí pongo el código que tengo en mi fichero:
> >>> >>
> >>> >> #!#!/Python26/python
> >>> >> from suds.client import Client
> >>> >> url = 'http://localhost:7789/?wsdl'
> >>> >> client = Client(url)
> >>> >> saludo = client.service.say_hello('punk', 5)
> >>> >> print saludo
> >>> >>
> >>> >> Les agradecería si me dieran una mano con esto.
> >>> >> _______________________________________________
> >>> >> Python-es mailing list
> >>> >> Python-es en python.org
> >>> >> http://mail.python.org/mailman/listinfo/python-es
> >>> >> FAQ: http://python-es-faq.wikidot.com/
> >>> >>
> >>> >
> >>> > --
> >>> > Enviado desde mi dispositivo móvil
> >>> > _______________________________________________
> >>> > Python-es mailing list
> >>> > Python-es en python.org
> >>> > http://mail.python.org/mailman/listinfo/python-es
> >>> > FAQ: http://python-es-faq.wikidot.com/
> >>> >
> >>> _______________________________________________
> >>> Python-es mailing list
> >>> Python-es en python.org
> >>> http://mail.python.org/mailman/listinfo/python-es
> >>> FAQ: http://python-es-faq.wikidot.com/
> >>>
> >>
> >
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20111114/4c66ef37/attachment.html>


Más información sobre la lista de distribución Python-es