Quiero saber como construir una consulta sql en la que el parámetro where ='recurso'
sea la variable recurso = soup.find('input', {'id': 'recurso'}).get('value')
Lo que quiero es que el select
obtenga los registros filtrado por la variable recurso
@app.route('/', methods=['GET', 'POST'])
def obtieneDatos():
global url
global contratista
global recurso
global vigencia
if request.method == 'POST':
url = request.form['scan']
html = requests.get(url, verify=False)
content = html.content
soup = b(content, "lxml")
contratista = soup.find('input', {'id': 'contratista'}).get('value')
recurso = soup.find('input', {'id': 'recurso'}).get('value')
vigencia = soup.find('input', {'id': 'vigencia'}).get('value')
urlImagen = soup.find("img").get("src")
urlImagen = urlImagen.replace('amp;', '')
contratista = contratista
recurso = recurso
vigencia = vigencia
conexion_MySQLdb = connectionBD()
cur = conexion_MySQLdb.cursor()
cur.execute("""
SELECT * FROM movingresos
INNER JOIN ingresos on movingresos.IdIngreso = ingresos.idIngreso
WHERE ingresos.recurso = 'recurso'
order by ingresos.recurso DESC , movingresos.estado DESC LIMIT 1;""")
conexion_MySQLdb.commit()
cur.close() #Cerrando conexion SQL
conexion_MySQLdb.close() #cerrando conexion de la BD
return render_template('public/dashboard/home.html', contratista = contratista, recurso = recurso, vigencia = vigencia, dataLogin = dataLoginSesion())
Intenté de la siguente manera pero me da error.
@app.route('/', methods=['GET', 'POST']) def obtieneDatos():
global url
global contratista
global recurso
global vigencia
if request.method == 'POST':
url = request.form['scan']
html = requests.get(url, verify=False)
content = html.content
soup = b(content, "lxml")
contratista = soup.find('input', {'id': 'contratista'}).get('value')
recurso = soup.find('input', {'id': 'recurso'}).get('value')
vigencia = soup.find('input', {'id': 'vigencia'}).get('value')
urlImagen = soup.find("img").get("src")
urlImagen = urlImagen.replace('amp;', '')
contratista = contratista
recurso = recurso
vigencia = vigencia
conexion_MySQLdb = connectionBD()
cur = conexion_MySQLdb.cursor()
sql=("""
SELECT * FROM movingresos
INNER JOIN ingresos on movingresos.IdIngreso = ingresos.idIngreso
WHERE ingresos.recurso =(s%)
order by ingresos.recurso DESC , movingresos.estado DESC LIMIT 1;""")
cur.execute(sql, recurso)
conexion_MySQLdb.commit()
cur.close() #Cerrando conexion SQL
conexion_MySQLdb.close() #cerrando conexion de la BD
return render_template('public/dashboard/home.html', contratista = contratista, recurso = recurso, vigencia = vigencia, dataLogin = dataLoginSesion())
ERROR
ProgrammingError mysql.connector.errors.ProgrammingError: Could not process parameters: str(BATTAGLINO CARLOS), it must be of type list, tuple or dict
Traceback (most recent call last)
File "C:\Login flask mysql\env\lib\site-packages\flask\app.py", line 2548, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Login flask mysql\env\lib\site-packages\flask\app.py", line 2528, in wsgi_app
response = self.handle_exception(e)
File "C:\Login flask mysql\env\lib\site-packages\flask\app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "C:\Login flask mysql\env\lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Login flask mysql\env\lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Login flask mysql\env\lib\site-packages\flask\app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "C:\Login flask mysql\app\app.py", line 214, in obtieneDatos
cur.execute(sql, recurso)
File "C:\Login flask mysql\env\lib\site-packages\mysql\connector\cursor.py", line 562, in execute
raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Could not process parameters: str(BATTAGLINO CARLOS), it must be of type list, tuple or dict