Python - AttributeError: 'NoneType' object has no attribute 'close'

 
Vista:

AttributeError: 'NoneType' object has no attribute 'close'

Publicado por Henry (1 intervención) el 08/11/2022 03:48:35
HOLA TENGO EL SIGUIENTE ERROR: AttributeError: 'NoneType' object has no attribute 'close'
SI ALGUIEN PUDIERA AYUDARME CON LA SOLUCION

@app.route("/download/report/pdf", methods=["GET", "POST"])
def download_report():
conn = None
cursor = None
try:
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute("SELECT * FROM control")
result = cursor.fetchall()

pdf = FPDF()
pdf.add_page()

page_width = pdf.w - 2 * pdf.l_margin

pdf.set_font('Arial', 'B', 12.0)
pdf.cell(page_width, 0.0, 'Control Data', align='C')
pdf.ln(10)

pdf.set_font('Arial', '', 11.0)

col_width = page_width/12
pdf.ln(1)

th = pdf.font_size

for row in result:
pdf.cell(col_width, th, row['operador_turistico'], border=1)
pdf.cell(col_width, th, str(row['serie'], border=1))
pdf.cell(col_width, th, str(row['boleto'], border=1))
pdf.cell(col_width, th, str(row['fecha_ventaboleto'], border=1))
pdf.cell(col_width, th, str(row['estado_boleto'], border=1))
pdf.cell(col_width, th, str(row['fecha_ingresoboleto'], border=1))
pdf.cell(col_width, th, str(row['pvc'], border=1))
pdf.cell(col_width, th, str(row['estado_boleto1'], border=1))
pdf.cell(col_width, th, str(row['fecha_ingresoboleto1'], border=1))
pdf.cell(col_width, th, str(row['pvc1'], border=1))
pdf.cell(col_width, th, str(row['estado_boleto2'], border=1))
pdf.cell(col_width, th, str(row['pvc2'], border=1))
pdf.ln(th)

pdf.ln(10)

pdf.set_font('Arial', '', 10.0)
pdf.cell(page_width, 0.0, '- end of report -', align='C')

return Response(pdf.output(dest='S').encode('latin-1'), mimetype='application/pdf', headers={'Content-Disposition':'attachment;filename=employee_report.pdf'})

except Exception as e:
print(e)
finally:

cursor.close()
conn.close()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 2.808
Oro
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

AttributeError: 'NoneType' object has no attribute 'close'

Publicado por tincopasan (1082 intervenciones) el 08/11/2022 05:27:46
marcá como comentario cursor.close() si lo que cerras es la conexión con conn.close()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar