[pyar] [OT] CURL con PHP....

Ramiro Algozino algozino en gmail.com
Mar Sep 21 13:29:31 ART 2010


2010/9/21 Roberto Bozzacchi <robbie en metasigno.com>:
> El tema es que se lo estoy pasando desde un PHP....
>
> Esta es la línea que llama el PHP al Python....
> exec("./envia.py $cel $sms",$output,$retsal);
>
> En donde $sms tiene el texto....
>
> Esta mal, no?
>
>
> El 21 de septiembre de 2010 13:13, Ramiro Algozino <algozino en gmail.com>
> escribió:
>>
>> 2010/9/21 Roberto Bozzacchi <robbie en metasigno.com>:
>> > Solucioné el error, pero ahora me pasa que el mensaje que pongo en el
>> > formulario PHP me lo corta y solo me manda la primer palabra:
>> >
>> > #!/usr/bin/python
>> >
>> > import sys, httplib
>> >
>> >
>> > if len(sys.argv) < 3:
>> >     print "usage: ./envia.py <cel> <msj>"
>> >     exit(1)
>> >
>> > cel = sys.argv[1]
>> > msj = sys.argv[2]
>> > #template de xml
>> >
>> > xmlTemplate = """
>> > <MTRequest>
>> > <Proveedor Id="extpindw" Password="frd2k10pltostd"/>
>> > <Servicio Id="66845.movistar.ar" ContentType="0"/>
>> > <Telefono msisdn=\""""+cel+"""\" IdTran="0"/>
>> > <Contenido>"""+msj+"""</Contenido>
>> > </MTRequest>
>> > """
>> >
>> > Ahí toma el segundo argumento, ahora, por que solo toma una palabra?
>> > Cómo puedo hacer que tome todo un texto?
>> >
>> >
>> > 2010/9/21 Roberto Bozzacchi <robbie en metasigno.com>
>> >>
>> >> Sigo con esto de encontrar la vuelta a la integración con un gateway de
>> >> SMS....
>> >>
>> >> Tengo este Código Python:
>> >>
>> >> #!/usr/bin/python
>> >>
>> >> import sys, httplib
>> >>
>> >>
>> >> if len(sys.argv) < 3:
>> >>     print "usage: ./envia.py <cel> <msj>"
>> >>     exit(1)
>> >>
>> >> cel = sys.argv[1]
>> >> msj = sys.argv[2]
>> >> #template de xml
>> >>
>> >> xmlTemplate = """
>> >> <MTRequest>
>> >> <Proveedor Id="extpindw" Password="frd2k10pltostd"/>
>> >> <Servicio Id="66845.movistar.ar" ContentType="0"/>
>> >> <Telefono msisdn=\""""+cel+"""\" IdTran="0"/>
>> >> <Contenido>"""+msj+"""</Contenido>
>> >> </MTRequest>
>> >> """
>> >>
>> >>
>> >> print "request:", xmlTemplate
>> >>
>> >> #construct and send the header
>> >>
>> >> webservice = httplib.HTTP("200.55.6.53:6079")
>> >> webservice.putrequest("POST", "http://200.55.6.53:6079/pindw")
>> >> webservice.putheader("Host", "200.55.6.53")
>> >> webservice.putheader("User-Agent", "Python post")
>> >> webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
>> >> webservice.putheader("Content-length", "%d" % len(xmlTemplate))
>> >> webservice.endheaders()
>> >> webservice.send(xmlTemplate)
>> >>
>> >> # get the response
>> >>
>> >> statuscode, statusmessage, header = webservice.getreply()
>> >> print "Response: ", statuscode, statusmessage
>> >> print "headers: ", header
>> >> res = webservice.getfile().read()
>> >> print res
>> >>
>> >>
>> >> Que es llamado desde un formulario en PHP....
>> >>
>> >> El tema es que me devuelve este error:
>> >>
>> >> Response: 400 Bad Request
>> >> headers: Content-type: text/html
>> >> Connection: close
>> >> Date: Tue, 21 Sep 2010 15:11:28 GMT
>> >> Server: Bombo/2.0
>> >>
>> >> Error 400
>> >>
>> >> Bad Request
>> >>
>> >> ________________________________
>> >> Bombo GW version 2.0
>> >> © Bombo Info - 2004
>> >>
>> >> Alguien tiene idea?
>> >>
>> >> --
>> >>
>> >> Robbie Bozzacchi
>> >> Metasigno Brain
>> >
>> >
>> >
>> > --
>> >
>> > Robbie Bozzacchi
>> > Metasigno Brain
>> >
>> > _______________________________________________
>> > pyar mailing list pyar en python.org.ar
>> > http://listas.python.org.ar/listinfo/pyar
>> >
>> > PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>> >
>>
>> le estas pasando todo el texto entre "" ?? si no por cada espacio que
>> tengas en el mensaje vas a tener un argumento nuevo..
>> ej:
>>
>> ./envia.py 6321789218 "mi mensaje de texto"
>>
>> Ahi sys.argv[2] va a ser el mensaje completo..
>>
>> Saludos!
>>
>> --
>> Ramiro Algozino
>> _______________________________________________
>> pyar mailing list pyar en python.org.ar
>> http://listas.python.org.ar/listinfo/pyar
>>
>> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
>
>
> --
>
> Robbie Bozzacchi
> Metasigno Brain
>
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>

Probá con:

exec("./envia.py $cel \"$sms\"",$output,$retsal);

-- 
Ramiro Algozino



More information about the pyar mailing list