I meet a weird error when downloading and executing a file in Windows 64 with the below code. The error is that I always get the access denied. Note that this code works fine in Linux and when I use Window Explorer to manually set full permissions to the file, I can execute it (I don't know why as my code already sets full permissions to the file).
#open url
u = urllib2.urlopen(download_url)
#create and write to a local file
with open(filename, 'wb') as f:
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
f.write(buffer)
#set full permission to the file
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
os.system(filename)
根据文档 , os.chmod
只能在Windows系统上设置更改只读权限。
看来问题是由我的人偶配置引起的,而不是python引起的,因为在父目录中设置权限存在问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.