如何解决为什么会出现错误“ AttributeError:'MySQLCursor'对象没有属性'exceute'”?
我正在使用Flask和Python创建基于CRUD的Web应用。
这里是链接:https://zcds4327.pythonanywhere.com/
这是存储库的链接:https://github.com/OCTRACORE/cs_proj_pro_1
树结构:
.
├── Password_creator.py
├── __pycache__
│ ├── Password_creator.cpython-38.pyc
│ ├── exec_prog.cpython-38.pyc
│ ├── global_data.cpython-38.pyc
│ └── table.cpython-38.pyc
├── exec_prog.py
├── global_data.py
├── passwd_file
├── requirements.txt
├── start.sh
├── static
│ ├── AddPasswdInp.css
│ ├── dispManipMenu.css
│ ├── favicon_io
│ │ ├── android-chrome-192x192.png
│ │ ├── apple-touch-icon.png
│ │ ├── favicon-32x32.png
│ │ ├── favicon.ico
│ │ └── site.webmanifest
│ ├── input.css
│ ├── show.css
│ └── showOutput.css
├── table.py
└── template
├── add.html
├── file-manip.html
├── input.html
├── modify.html
├── output_disp.html
├── semantic-error.html
└── str_main.html
代码的父目录: cs_proj_pro_1
代码段(来自exec_prog.py)
@app.route('/generate/file-manip',methods = ["GET","POST"]) # for saving the password(s)
def save_file():
pass_output_lst = [] #for passwords
desc_output_lst = [] #for descriptions of the password
encrypted_pass_output_lst = [] #storing passwords after encryption
encrypted_desc_output_lst = [] #storing descriptions of passwords after encryption
UPLOAD_FOLDER = os.getcwd()
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
if request.method == "POST": # checking if the request method is POST
pass_file = request.files['passfile'] #requesting the name of the password saving file
pass_file_Name = secure_filename(pass_file.filename) #storing the name of the password saving file
desc_file = request.files['descfile'] #for the file storing descriptions of the file
desc_file_Name =secure_filename(desc_file.filename)
key = Fernet.generate_key() # generating a key
key_init = Fernet(key) # storing the key for encrypting purpose
key_file = request.files['keyfile'] # requesting the key saving file
key_file_name = secure_filename(key_file.filename) #storing the name of the key saving file
file_lst = [pass_file_Name,desc_file_Name,key_file_name]
for i in globalData.password:
encrypted_pass_output_lst.append(key_init.encrypt(bytes(i.passwd,encoding="utf-8")))
encrypted_desc_output_lst.append(key_init.encrypt(bytes(i.desc,encoding="utf-8")))
with open(pass_file_Name,"wb+") as k:
for i in encrypted_pass_output_lst:
k.write(i)
k.write(b'\n')
with open(desc_file_Name,"wb+") as k:
for i in encrypted_desc_output_lst:
k.write(i)
k.write(b'\n')
with open(key_file_name,"wb+") as k:
k.write(key)
if globalData.password == []: # for showing the error when no password is created
return render_template('semantic-error.html',message = "Illegal method. Can't save the file when no password is generated")
else: #[pass_file_Name,key_file_name]
zip_obj = zipfile.ZipFile('/home/ZCDS4327/proj/cs_proj_pro_1/zipfile.zip','w')#creating a zip file and storing it inside an object
#sql Execution(an sql table stores number of password generated by the user along with it's date and time)
getDate = datetime.datetime.Now() #date and time of generating the passwords
cursor = mydb.cursor()
n_passwd = len(globalData.password) #number of passwords generated
insert_query = "INSERT INTO password_table(n_passwd,c_date) VALUES(%s,%s)" %(n_passwd,getDate) #inserting the passwords inside the table password_site
cursor.exceute(insert_query)
mydb.commit()
for i in file_lst:
zip_obj.write(i,compress_type =zipfile.ZIP_DEFLATED) #inserting the required files inside the zip file
zip_obj.close()
zip_obj_name = zip_obj.filename
for i in file_lst:
os.remove(i) #removing the txt files
del file_lst
return send_file(zip_obj_name),os.remove('/home/ZCDS4327/proj/cs_proj_pro_1/zipfile.zip') #downloading the zipfile and deleting it from the working directory
工作目录:
/home/ZCDS4327/proj/cs_proj_pro_1
使用的环境:任意位置的Python
用户可以通过加密将生成的密码及其相应的说明存储在两个不同的文本文件中。另外,还向用户提供了另一个包含用于加密的密钥的文本文件。然后将包含这些文件的zip文件下载到用户的设备。
在此过程中,将执行SQL查询,其中存储用户生成的密码数量以及执行任务的日期和时间。
#sql Execution(an sql table stores number of password generated by the user along with it's date and time)
getDate = datetime.datetime.Now() #date and time of generating the passwords
cursor = mydb.cursor()
n_passwd = len(globalData.password) #number of passwords generated
insert_query = "INSERT INTO password_table(n_passwd,getDate) #inserting the passwords inside the table password_site
cursor.exceute(insert_query)
mydb.commit()
但是当我执行测试过程的任务时,却收到了内部服务器错误。
2020-10-16 12:48:44,016: Exception on /generate/file-manip [POST]
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/flask/app.py",line 2446,in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3.8/site-packages/flask/app.py",line 1951,in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3.8/site-packages/flask/app.py",line 1820,in handle_user_exception
reraise(exc_type,exc_value,tb)
File "/usr/lib/python3.8/site-packages/flask/_compat.py",line 39,in reraise
raise value
File "/usr/lib/python3.8/site-packages/flask/app.py",line 1949,in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3.8/site-packages/flask/app.py",line 1935,in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ZCDS4327/proj/cs_proj_pro_1/exec_prog.py",line 149,in save_file
cursor.exceute(insert_query)
AttributeError: 'MysqLCursor' object has no attribute 'exceute'
即使试图通过在互联网上搜索找到该错误,我也没有发现有用的东西。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。