我是蟒蛇和樱桃的新手。我正在尝试使用以下代码上载文件:
@cherrypy.tools.noBodyProcess()
def POST(self,theFile=None):
lcHDRS = {}
for key, val in cherrypy.request.headers.iteritems():
lcHDRS[key.lower()] = val
formFields = myFieldStorage(fp=cherrypy.request.rfile,
headers=lcHDRS,
environ={'REQUEST_METHOD':'POST'},
keep_blank_values=True)
dt = datetime.now()
date = dt.strftime('%Y-%m-%d')
dt = dt.strftime('%Y%m%d%H%M%S')
theFile = formFields['theFile']
theFile.filename = str(dt) + "file"
shutil.copy2(theFile.file.name,os.path.join(absolutePath , theFile.filename))
...
...
我检查了路径os.path.join(absolutePath,file.filename),它是正确的。
问题是代码在Linuxubuntu上运行良好,但在windows上运行不好。
调用的错误为:
已编辑
shutil.copy2(theFile.file.name,settings.UPLOAD_FILE_PATH + theFile.filename)
File "C:\Anaconda\lib\shutil.py", line 130, in copy2
copyfile(src, dst)
File "C:\Anaconda\lib\shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 13] Permission denied: 'c:\\users\\username\\appdata\\local\\temp\\tmpjy3gys'
我哪里出错了?
如果你需要任何其他信息,请告诉我。