Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

367
Vistas
shell_exec ()in php does not execute in for loop in script python

Hello gears I'm trying to run a python script from a site, following your recommendation I use ajax but it brings me back the python code and does not execute the code.

Here is the code on the browser side

<script>

 document.getElementById("button").onclick = function () {
    $.ajax({
        type: 'POST',
        url: "projet.py",
        data: {param: ""}, //passing some input here
        success: function(response){
           console.log(output);
        }
     })
  };

</script>

  <div class="button" id="button">
    Start
</div>
  #!/usr/bin/python3
import pymysql.cursors
import time
import serial

# Connect to the database
connection = pymysql.connect(host='localhost',
                             user='root',
                             password='******',
                             database='iot',
                             charset='utf8mb4',
                             cursorclass=pymysql.cursors.DictCursor)
time.sleep(0.5)

while 1 :
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
    ser.flush()
    while True:
        if ser.in_waiting > 0:
            line = ser.readline().decode('utf-8').rstrip()
            print("Valeur recu :{}".format(line))
            break
    time.sleep(0.5)
    with connection:
        with connection.cursor() as cursor:
            # Create a new record
            sql = "INSERT INTO `tension` (`valeur`) VALUES (%s)"
            cursor.execute(sql, (line))

        # connection is not autocommit by default. So you must commit to save
        # your changes.
        connection.commit()
        time.sleep(0.5)
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda