Hola a todos. Además de descubrir como funciona wget, sigo buscando la causa de que un sencillo programa funcione en un Servidor con Python 2.6 y no lo haga con Python 2.7. Para ello he forzado la versión así:
#!/usr/bin/env python2.6 A pesar de forzar la versión, en el Servidor que falla, el error lo da en un módulo situado en Python 2.7 File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__ raise KeyError(key) KeyError: 'SCRIPT_NAME' Siguiendo el consejo de Edison, adjunto los dos módulos que conforman el programa. Muchas gracias por vuestra ayuda. :-) El 26 de agosto de 2015, 23:52, Juan M. Puertas <soft.sir...@gmail.com> escribió: > Muchas gracias por vuestra ayuda. > Resulta que he descargado en el Servidor el archivo python con wget, y al > parecer wget sólo toma la parte html del archivo y no la parte Python. > Desconozco lo que hace wget, pero creo que esa es la causa. > Todos los días se aprende algo. > Saludos. :-) > > > El 26 de agosto de 2015, 23:27, Edison Ibañez <edi...@openmailbox.org> > escribió: > >> Si es un error de sintaxis, pasalo con pep8 para que identifiques el error >> >> ejecuta en la terminal: >> >> sudo pip install flake8 >> >> flake8 --ignore=E221,E701,E202 archivo.py >> >> El 26/08/15 a las 16:17, Juan M. Puertas escribió: >> > Hola Alex. >> > En FTP tenía bien el usuario "root" pero sigue sin darme acceso. Pongo >> > lo siguiente: >> > Servidor 195.114.210.208 >> > Usuario root >> > Y la contraseña que me has enviado. Me da error crítico, no se pudo >> > conectar al Servidor. >> > ¿Con los datos que me has dado tú puedes entrar bien por FTP? >> > >> > He probado con un programa pequeñito que hace una multiplicación >> > mediante sajax1.py, se llama multiply.py . Resulta que en mi Servidor >> > funciona bien, y en el vuestro da error. Esto es algo muy, muy extraño. >> > Aún más extraño: cuando uso vi para ver el archivo multiply.py, sólo >> > aparece la parte html, no la que está en Python, en mi Servidor se ve >> > todo, es extraño total, cualquiera diría que vuesto Servidor tiene un >> > duende :-)) >> > Necesito FTP, para ver mejor qué pasa cuando envío el archivo. >> > Saludos. >> > >> > El 26 de agosto de 2015, 23:02, Juan M. Puertas <soft.sir...@gmail.com >> > <mailto:soft.sir...@gmail.com>> escribió: >> > >> > Hola. >> > He forzado al programa para que utilice la versión 2.6 así: >> > #!/usr/bin/env python2.6 >> > y el error persiste, >> > :-? >> > >> > >> > El 26 de agosto de 2015, 22:31, Juan M. Puertas >> > <soft.sir...@gmail.com <mailto:soft.sir...@gmail.com>> escribió: >> > >> > Hola Kiko. >> > He hecho lo siguiente por consola: >> > >> > |$readlink -f $(which python)|xargs -I %sh -c 'echo -n "%: "; % >> -V'| >> > >> > Y devuelve: >> > /usr/bin/python2.7: Python 2.7.3 >> > >> > Es extraño que con esta versión el programa de el error que da, >> > no se me ocurre que pueda ser otra la causa. >> > >> > Gracias :-) >> > >> > El 26 de agosto de 2015, 21:35, Kiko <kikocorre...@gmail.com >> > <mailto:kikocorre...@gmail.com>> escribió: >> > >> > >> > >> > El 26 de agosto de 2015, 21:23, Juan M. Puertas >> > <soft.sir...@gmail.com <mailto:soft.sir...@gmail.com>> >> escribió: >> > >> > Hola amigos: >> > En un servidor con Ubuntu está instalada la versión >> > 2.6.5 y en otro servidor con Debian está instalada la >> > versión 2.7.3. >> > El programa comienza así: >> > >> >> ___________________________________________________________________________________ >> > #!/usr/bin/env python >> > import cgitb;cgitb.enable() >> > import sajax1 >> > >> > def multiply(x,y): >> > try: >> > float_x, float_y = float(x), float(y) >> > except: >> > return 0 >> > return float_x * float_y >> > >> > sajax1.sajax_init() >> > sajax1.sajax_export(multiply) >> > sajax1.sajax_handle_client_request() >> > >> > print """ >> > <html> >> > (...) >> > >> >> ____________________________________________________________________________________ >> > >> > En la versión 2.6.5 el programa funciona bien. >> > >> > En la versión 2.7.3 me dice: >> > <html> >> > ^ >> > SyntaxError: invalid syntax >> > >> > >> > >> > ¿ >> > Sabeis si existe una incompatibilidad entre ambas >> > versiones? >> > >> > >> > No debería. >> > >> > Estás seguro que estás usando python 2.7.3 en la máquina >> debian? >> > > which python >> > qué te indica? >> > >> > >> > Muchas gracias por vuestra ayuda :-) >> > >> > >> > _______________________________________________ >> > Python-es mailing list >> > Python-es@python.org <mailto:Python-es@python.org> >> > https://mail.python.org/mailman/listinfo/python-es >> > FAQ: http://python-es-faq.wikidot.com/ >> > >> > >> > >> > _______________________________________________ >> > Python-es mailing list >> > Python-es@python.org <mailto:Python-es@python.org> >> > https://mail.python.org/mailman/listinfo/python-es >> > FAQ: http://python-es-faq.wikidot.com/ >> > >> > >> > >> > >> > >> > >> > _______________________________________________ >> > Python-es mailing list >> > Python-es@python.org >> > https://mail.python.org/mailman/listinfo/python-es >> > FAQ: http://python-es-faq.wikidot.com/ >> > >> >> _______________________________________________ >> Python-es mailing list >> Python-es@python.org >> https://mail.python.org/mailman/listinfo/python-es >> FAQ: http://python-es-faq.wikidot.com/ >> > >
#!/usr/bin/env python2.6 import cgi import cgitb; cgitb.enable() import os import sys import datetime import urllib print "Content-type: text/html" sajax_debug_mode = False sajax_export_list = {} sajax_js_has_been_shown = False form = cgi.FieldStorage() def sajax_init(): pass def sajax_handle_client_request(): func_name = form.getfirst('rs') if func_name is None: return # Bust cache in the head print "Expires: Mon, 26 Jul 1997 05:00:00 GMT" print "Last-Modified: %s GMT" % datetime.datetime.utcnow().strftime( "%a, %d %m %H:%M:%S") # always modified print "Cache-Control: no-cache, must-revalidate" # HTTP/1.1 print "Pragma: no-cache" # HTTP/1.0 print if not func_name in sajax_export_list: print "-:%s not callable" % func_name else: print "+:", rsargs = form.getlist('rsargs[]') result = sajax_export_list[func_name](*rsargs) print result sys.exit() def sajax_get_common_js(): sajax_debug_modeJS = str(sajax_debug_mode).lower() return """\ // remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = %(sajax_debug_modeJS)s; function sajax_debug(text) { if (sajax_debug_mode) alert("RSD: " + text) } function sajax_init_object() { sajax_debug("sajax_init_object() called..") var A; try { A=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { A=new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { A=null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) sajax_debug("Could not create connection object."); return A; } function sajax_do_call(func_name, url, args) { var i, x, n; for (i = 0; i < args.length-1; i++) url = url + "&rsargs[]=" + escape(args[i]); url = url + "&rsrnd=" + new Date().getTime(); x = sajax_init_object(); x.open("GET", url, true); x.onreadystatechange = function() { if (x.readyState != 4) return; sajax_debug("received " + x.responseText); var status; var data; status = x.responseText.charAt(0); data = x.responseText.substring(2); if (status == "-") alert("Error: " + data); else args[args.length-1](data); } x.send(null); sajax_debug(func_name + " url = " + url); sajax_debug(func_name + " waiting.."); delete x; } """ % locals() def sajax_show_common_js(): print sajax_get_common_js() def sajax_esc(val): return val.replace('"', '\\\\"') def sajax_get_one_stub(func_name): uri = os.environ['SCRIPT_NAME'] if os.environ.has_key('QUERY_STRING'): uri += "?" + os.environ['QUERY_STRING'] + "&rs=%s" % urllib.quote_plus(func_name) else: uri += "?rs=%s" % urllib.quote_plus(func_name) escapeduri = sajax_esc(uri) return """ // wrapper for %(func_name)s function x_%(func_name)s(){ // count args; build URL sajax_do_call("%(func_name)s", "%(escapeduri)s", x_%(func_name)s.arguments); } """ % locals() def sajax_show_one_stub(func_name): print sajax_get_one_stub(func_name) def sajax_export(*args): decorated = [(f.func_name, f) for f in args] sajax_export_list.update(dict(decorated)) def sajax_get_javascript(): global sajax_js_has_been_shown html = '' if not sajax_js_has_been_shown: html += sajax_get_common_js() sajax_js_has_been_shown = True for func_name in sajax_export_list.iterkeys(): html += sajax_get_one_stub(func_name) return html def sajax_show_javascript(): print sajax_get_javascript()
#!/usr/bin/env python2.6 import cgitb;cgitb.enable() import sajax1 def multiply(x,y): try: float_x, float_y = float(x), float(y) except: return 0 return float_x * float_y sajax1.sajax_init() sajax1.sajax_export(multiply) sajax1.sajax_handle_client_request() print """ <html> <head> <title>PyMultiplier</title> <script> """ sajax1.sajax_show_javascript() print """ function do_multiply_cb(z) { document.getElementById("z").value = z; } function do_multiply() { var x, y; x = document.getElementById("x").value; y = document.getElementById("y").value; x_multiply(x, y, do_multiply_cb); } </script> </head> <body> <input type="text" name="x" id="x" value="2" size="3"> * <input type="text" name="y" id="y" value="3" size="3"> = <input type="text" name="z" id="z" value="" size="3"> <input type="button" name="check" value="Calculate" onclick="do_multiply(); return false;"> </body> </html> """ % locals()
_______________________________________________ Python-es mailing list Python-es@python.org https://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/