main.py當(dāng)我在路線之外使用cursor.execute..時(shí),它正在工作。import mysql.connectorfrom flask import Flask, render_template, request, session, redirect, url_for, make_responseMySQL = mysql.connector.connect( user='root', password='password', host='localhost', database='dbname', use_pure=True)cursor = MySQL.cursor(prepared=True)@app.route("/bridge", methods=["POST"])def bridge(): if request.get_json()["for"] == "signUp": if request.get_json()["type"] == "existence": cursor.execute("SELECT id FROM users WHERE eMail=%s", (request.get_json()["details"]["eMail"], )) print("----------------- {}".format(cursor.fetchone())) print(request.get_json()["details"]["eMail"]) return make_response(json.dumps({"Res"}), 200)cursor.close()MySQL.close()錯(cuò)誤cursor.execute("從電子郵件中選擇 id=%s", (request.get_json()["details"]["eMail"], )) 文件 "C:\Users\woxro\AppData\Local\Programs\ Python\Python38-32\Lib\site-packages\mysql\connector\cursor.py”,第 1186 行,執(zhí)行 charset = self._connection.charset AttributeError: 'NoneType' 對(duì)象沒(méi)有屬性 'charset'
1 回答

MM們
TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊
問(wèn)題是您創(chuàng)建連接并在調(diào)用橋之前關(guān)閉它。請(qǐng)參閱:MySQL.close()
這就是它在橋接方法之外工作的原因
添加回答
舉報(bào)
0/150
提交
取消