“ Errno 13 权限被拒绝 'bnr_code.csv'”?
" Errno 13 Permission denied 'bnr_code.csv'"?
我已经使用 apache2 和 wsgi 在服务器上部署了一个 Django 项目,它显示了一个错误,我可能知道它为什么会出现。
错误:
IOError at /
[Errno 13] Permission denied: 'bnr_code.csv'
Request Method: GET
Request URL: http://93.188.167.63:8080/pep_learn/
Django Version: 1.10.8
Exception Type: IOError
Exception Value:
[Errno 13] Permission denied: 'bnr_code.csv'
Exception Location: /home/pep_web/binaryDs/views.py in <module>, line 6
Python Executable: /usr/bin/python
Python Version: 2.7.12
我试过一些中伤的解决方案,如下所示:
chmod 777 pep_web/
chmod 771 pep_web/
sudo chown :www-data pep_web/
但没有任何效果
这是使用 'bnr_code.csv'
的文件
AA = {"A":"1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"C":"0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"D":"0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"E":"0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"F":"0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"G":"0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"H":"0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0",
"I":"0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0",
"K":"0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0",
"L":"0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0",
"M":"0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0",
"N":"0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0",
"P":"0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0",
"Q":"0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0",
"R":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0",
"S":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0",
"T":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0",
"V":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0",
"W":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0",
"Y":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1"}
line = []
seqs = ["ATTTRY","ATSSRY"]
def bnr(x):
Des = []
for n in x:
Des.append(AA[n.upper()])
des = ",".join(Des)
return des
def Des_write(ps):
f = open("bnr_code.csv",'w')
for p in ps:
a = bnr(p)
f.write(p+','+a+'\n')
f.close()
Des_write(seqs)
检查错误
不要使用文件的相对路径,使用绝对路径。 mod_wsgi.
的文档中解释了此问题
通过执行以下操作计算文件的位置:
filename = os.path.join(os.path.dirname(__file__), 'bnr_code.csv')
我已经使用 apache2 和 wsgi 在服务器上部署了一个 Django 项目,它显示了一个错误,我可能知道它为什么会出现。
错误:
IOError at /
[Errno 13] Permission denied: 'bnr_code.csv'
Request Method: GET
Request URL: http://93.188.167.63:8080/pep_learn/
Django Version: 1.10.8
Exception Type: IOError
Exception Value:
[Errno 13] Permission denied: 'bnr_code.csv'
Exception Location: /home/pep_web/binaryDs/views.py in <module>, line 6
Python Executable: /usr/bin/python
Python Version: 2.7.12
我试过一些中伤的解决方案,如下所示:
chmod 777 pep_web/
chmod 771 pep_web/
sudo chown :www-data pep_web/
但没有任何效果
这是使用 'bnr_code.csv'
的文件AA = {"A":"1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"C":"0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"D":"0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"E":"0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"F":"0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"G":"0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
"H":"0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0",
"I":"0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0",
"K":"0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0",
"L":"0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0",
"M":"0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0",
"N":"0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0",
"P":"0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0",
"Q":"0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0",
"R":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0",
"S":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0",
"T":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0",
"V":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0",
"W":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0",
"Y":"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1"}
line = []
seqs = ["ATTTRY","ATSSRY"]
def bnr(x):
Des = []
for n in x:
Des.append(AA[n.upper()])
des = ",".join(Des)
return des
def Des_write(ps):
f = open("bnr_code.csv",'w')
for p in ps:
a = bnr(p)
f.write(p+','+a+'\n')
f.close()
Des_write(seqs)
检查错误
不要使用文件的相对路径,使用绝对路径。 mod_wsgi.
的文档中解释了此问题通过执行以下操作计算文件的位置:
filename = os.path.join(os.path.dirname(__file__), 'bnr_code.csv')