问题描述
我有一个程序可以打开一个 csv 文件并对其执行一些魔术。无论如何在周五它正常工作,但今天在我重新启动我的虚拟机后,无论我尝试打开什么 .csv 文件,它都会返回这个错误:
权限错误:[Errno 13] 权限被拒绝:'C:/Users/admin.ab/export_1.csv'
无论文件在哪个目录,它仍然显示相同的路径。
谁能解释一下为什么会突然发生这种情况?
我已经阅读了仅发生在一个文件或他们试图打开路径的问题。 我尝试了来自不同用户的不同文件。它总是返回相同的错误,只是它更改的是文件名 - 因为打开了不同的文件。
编辑
这是它读取文件的代码:
@app.route('/filtered_file',methods=['GET','POST'])
@login_required
def open_file():
'''Opens page with the file that was imported from the user.'''
if request.method == 'POST':
#check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return render_template('choose_file.html')
#check if the right CSV file was selected
file_upload = request.files['file']
#check if the uploaded file a CSV file is
if file_upload and allowed_file(file_upload.filename):
filename = secure_filename(file_upload.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'],filename)
file_upload.save(file_path)
file_to_filter = pd.read_csv(file_path,sep=';',engine='python',encoding='utf-8-sig') #ISO-8859-1
table1 = filter_csv(file_to_filter)
table2 = table1.to_html(classes='my_class" id = "my_id')
os.remove(os.path.join(app.config['UPLOAD_FOLDER'],filename))
return render_template('filtered_file.html',data=table2)
return render_template('choose_file.html')
第二部分:
#only be able to import the csv file and nothing else
allowed_extensions = set(['csv'])
def allowed_file(filename):
'''Function used to check if the file imported is equal=csv'''
return '.' in filename and filename.rsplit('.',1)[1].lower() in
allowed_extensions
解决方法
我有一些你可以尝试的指针。出现此错误的原因可能有很多,但以下是一些常见和流行的原因
-
文件或文件的父文件夹权限。
- 检查文件(您的 .py 文件以及 .csv 文件)UGO 权限
- 检查父文件夹 UGO 权限
-
您的文件/文件夹可能被其他一些 Python 程序错误地打开。
-
如果您启用了多线程,那么情况 2 也会发生
-
内部包/pip 更新问题(有漏洞的更新)。罕见的情况,但会发生。